atmega48 SPI stops working when delay in main loop

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

Consider the code in the following git folder:

 

https://github.com/randohinn/AVR/tree/master/NRF24L01

 

The code in main.c exhibits a flaw, where, if I uncomment the delay in the while loop, the chip does not do any SPI anymore. All communications stop. Even no SPI clock from the AVR.. If I, however, add a pin blink after said delay, the pin does blink, and does so with 1s delay, so it's not completely crashing. Remove the delay - works fine. What affects the SPI so much here? F_CPU is correct, I'm using the default fuses with CLKDIV8 turned off as the only modification...

Last Edited: Wed. May 22, 2019 - 01:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If I had to guess I would wonder if perhaps the radio sleeps if you don't talk to it for a while (like 500ms) ? Do you have to keep doing something to keep it awake perhaps? (in which case break the 500ms into 10 lots of 50ms or whatever and keep tickling it).

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

clawson wrote:

If I had to guess I would wonder if perhaps the radio sleeps if you don't talk to it for a while (like 500ms) ? Do you have to keep doing something to keep it awake perhaps? (in which case break the 500ms into 10 lots of 50ms or whatever and keep tickling it).

 

Well, the AVR is not outputting SPI clock even, so it's the AVR side that derps, not the radio sleeping. Edited OP to include this. 

 

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

SPIs that do not do SCK usually mean MSTRs that have stopped being Masters. That happens if they see a LOW on the SS pin. I'll have to look at your code again to see what you are doing with SS (hopefully you have it as an output and it's being used to slave select the radio?)

 

EDIT: Ah OK, you are handling mega48 PB2 ("SS") - then that is a mystery, 99 times out of 100 that IS the reason why SPI stops doing SCK.

Last Edited: Wed. May 22, 2019 - 01:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

SPIs that do not do SCK usually mean MSTRs that have stopped being Masters. That happens if they see a LOW on the SS pin. I'll have to look at your code again to see what you are doing with SS (hopefully you have it as an output and it's being used to slave select the radio?)

 

EDIT: Ah OK, you are handling mega48 PB2 ("SS") - then that is a mystery, 99 times out of 100 that IS the reason why SPI stops doing SCK.

 

Yup. I did fall victim to the SS line thing when I first tried to write this a week ago, so I quickly figured that out :D