Porting LwMEsh to Atmega1284p

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Having problems with the SPI after using this code and porting it to Atmega1284p.

 

Can you se the image?
<img src="Capture.JPG" alt="logic_analysor_of_spi" width="95%">

I tried to port it to atmega1284p from atmega1281,

Heres a list of changes

in solution properties:

  1. AVR/GNU C-compiler - Directories: (I changed paths to my 1284p and at86rf212)
  2. AVR/GNU C-compiler - Symbols: (I changed to PHY_AT86RF212, HAL_ATMEGA1284P, PLATFORM_XPLAINED)
  3. Searching the documents for my previous values and changed them to my respective new values. The following documents where changed to the value "PHY_AT86RF212": phy.c, config.h, Peer2Peer.c, 
    Searching for HAL_ATMEGA1284P, gives changes in: sysTypes.h
    Searchin for PLATFORM_XPLAINED gives changes in: halPhy.h
  4. Then I changed the the file halPhy.h so that the defined platform is linked to the right pins:

#if defined(PLATFORM_XPLAINED)
// Rz600 radio module connected to J1
    HAL_GPIO_PIN(PHY_RST,    C, 1);
    HAL_GPIO_PIN(PHY_IRQ,    D, 0);
    HAL_GPIO_PIN(PHY_SLP_TR, D, 1);
    HAL_GPIO_PIN(PHY_CS,     B, 4);
    HAL_GPIO_PIN(PHY_MISO,   B, 6);
    HAL_GPIO_PIN(PHY_MOSI,   B, 5);
    HAL_GPIO_PIN(PHY_SCK,    B, 7);
#endif

  1. My last change was in halTimer.c, where the clock is set to Timer3 insted of Timer4.

void HAL_TimerInit(void)
{
    halTimerIrqCount = 0;

    OCR3A = ((F_CPU / 1000ul) / TIMER_PRESCALER) * HAL_TIMER_INTERVAL;
    TCCR3B = (1 << WGM32);              // CTC mode
    TCCR3B |= (1 << CS31);              // Prescaler 8
    TIMSK3 |= (1 << OCIE3A);            // Enable TC3 interrupt
}

/*************************************************************************//**
*****************************************************************************/
void HAL_TimerDelay(uint16_t us)
{
PRAGMA(diag_suppress=Pa082);

OCR3B = TCNT3 + us;
if (OCR3B > OCR3A)
OCR3B -= OCR3A;

TIFR3 = (1 << OCF3B);
while (0 == (TIFR3 & (1 << OCF3B)));

PRAGMA(diag_default=Pa082);
}

/*************************************************************************//**
*****************************************************************************/
ISR(TIMER3_COMPA_vect)
{
halTimerIrqCount++;
}

 

The output is totally wrong, and I cannot initialise the phy part according to the debugger.
I get to line 331 in phy.c 
while static void phyWaitState(uint8_t state)
{
  while (state != (phyReadRegister(TRX_STATUS_REG) & TRX_STATUS_MASK));
}

The problem is that state=8
phyReadRegister(TRX_STATUS_REG) = 0b0000 0000

and status mask = 0b0001 1111
And I cannot understand what this function does and how the function will return a result to be 8?

Attachment(s): 

This topic has a solution.
Last Edited: Fri. Oct 16, 2015 - 12:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MOD: Please start new threads for separate issues.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

It looks like your radio may not be connected properly. Have you tried a scope or a logic analyzer?

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Also, what exactly did you change in phy.c? You don't need to change anything, you just need to point to a different file.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I am using a logic analyzer, a cheap one from ebay, maybe my resoulution is too low, my logic analyser samples at 1mhz.

 

In phy.c I changed line 47:

 

#ifdef PHY_AT86RF212

EDIT: I did not change this, I added this file as a link, no change was done.

 

Last Edited: Thu. Aug 20, 2015 - 08:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Well, that's wrong. You need to change file paths to actually point to the right PHY. You should never edit actual PHY files.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did not change this file (phy.c) , I just had to change folders and add the right rf212.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Then you did everything right, and the problem seems to be in the hardware. What hardware do you use for the radio?

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use Xplained 1284p, with the RZ600 kit, 2 pcs. AT86RF212 radio cards

The problem was my logic analyzer, it was not set to sample so fast. And thus the result looked wrong. Now it looks better. 

One problem is stil there, SYS_Init() does not work, it gets to line 311 in phy.c using debugger.

static void phyWaitState(uint8_t state)
{
  while (state != (phyReadRegister(TRX_STATUS_REG) & TRX_STATUS_MASK));
}
 

This is where it stops in the debugger, it is waiting for  the statement to evaluate to 8.
or should I say, state=8, and the (phyReadRegister(TRX_STATUS_REG) & TRX_STATUS_MASK) must also evaluate to 8.

Last Edited: Fri. Aug 21, 2015 - 06:37 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

This is a good sign that there is something wrong with the hardware.

 

You may try to lower SPI frequency, but I doubt it will change anything. Double check that non-SPI signals are also connected properly, especially reset and slp_tr.

 

What frequency your MCU is running at?

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So I double checked all connections from the SPI out on the MCU, They all go into the right header pin on the rfcard. Only change is MISO_MCU goes into MOSI_rf and other way around. 

EDIT:
I just tested to change those pins, so now MISO is to MISO and MOSI to MOSI. And the device inits perfectly. I just sent something between the devices, the baud was not correctly set for the uart, but I can fix that myself!
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

SPI signals are named this way so there is never a confusion between what "TX" and "RX" means :)

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello alexru I have a question: I'm in the function nwkTxTaskHandler and frame->state is NWK_TX_STATE_SENT and I've enabled ACK. This is the code:

 

case NWK_TX_STATE_SENT:
      {
        if (NWK_SUCCESS_STATUS == frame->tx.status)
        {
          if (frame->header.nwkSrcAddr == nwkIb.addr && frame->header.nwkFcf.ackRequest)
          {
            frame->state = NWK_TX_STATE_WAIT_ACK;
            frame->tx.timeout = NWK_ACK_WAIT_TIME / NWK_TX_ACK_WAIT_TIMER_INTERVAL + 1;
            SYS_TimerStart(&nwkTxAckWaitTimer);
          }
          else
          {
            frame->state = NWK_TX_STATE_CONFIRM;
          }
        }
        else
        {
          frame->state = NWK_TX_STATE_CONFIRM;
    }
      } break;

Where NWK_ACK_WAIT_TIME=NWK_TX_ACK_WAIT_TIMER_INTERVAL=10; The program enters in the if and sets the NWK_TX_STATE_WAIT_ACK state. I don't understand where the NWK_TX_STATE_CONFIRM is settled without have NWK_NO_ACK_STATUS (in the function nwkTxAckWaitTimerHandler) for req->status and so an error in AppDataConf (he doesn't enter in NWK_SUCCESS_STATUS==req->status anymore). Why the stack needs to wait for the ACK? In ATmega128RFA1 manual (pag 61) seems that the microcontroller gets ACK in TX_ARET transaction so if an ACK is expected it arrives before the TRX24_TX_END interrupt is called. Is that right? 

Thank you

P.s another strange thing that happens is that the TRX24_RX_END interrupt is called even if my micro only has to transmit. 

Hello everyone,

I'm an italian student and I'm working for my master work with the ATmega128RFA1 microcontroller. Hope you can help me and sorry for my english :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

MarcoScordo wrote:
I don't understand where the NWK_TX_STATE_CONFIRM is settled without have NWK_NO_ACK_STATUS
If I understand your question correctly, then you need to look at nwkTxAckReceived().

 

MarcoScordo wrote:
Why the stack needs to wait for the ACK?
They are different ACKs. The radio only handles MAC level ACKs, but in case of mesh routing you need to have (if requested by the application, of course) and ACK for the entire routing chain.

 

MarcoScordo wrote:
P.s another strange thing that happens is that the TRX24_RX_END interrupt is called even if my micro only has to transmit.
It also receives an ACK frame. Standalone radios suppress this interrupt, presumably because SPI interface is relatively slow.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.