so here is a weird question. i tried to search for it but ‘setup’ is so common that i never got what i was looking for.
basically i have a function that transfers data via SPI1. If i place the code in the setup() function i always get 0x00 as a response. If i move the same call to the loop() function i get what I expect.
can i not call things like SPI1.transfer() in setup(), only loop?
Sorry if this is an obvious question, but I just dont understand why it doesnt work in setup.
Also, my serial comms do not work in setup(), but work fine in loop().
thanks
Yes you can use SPI1 in setup. Assuming of course you initialized it first.
That is strange that the serial does not work either in setup. I suspect it’s something that you may not be doing correctly first prior to using them.
Also, external devices may need longer time to reset from POR, than the particle. What you could try in your setup() after you initialized SPI1, is to a short delay of say 150ms then read your device. Then after you read it, delay another 150ms and read it again. This will help diagnose where the issue may be.
1 Like
great, thanks for the tips! I will try tonight and post my code as well.