Page 1 of 1

SPI module as a slave

Posted: Tue Nov 08, 2022 1:43 pm
by Bruno
Hello at all
I have a question about PIC's spi module.
I am using a pic18F46k22 with spi module in slave mode but I have synchronization problems with the bytes I send from the master.
I have found an unorthodox way to synchronize received bytes, but sometimes this doesn't happen
This is the first time I use this mode of operation and I can't solve it.
Can someone help me
I am attaching the test file I am using

Thank you

Re: SPI module as a slave

Posted: Fri Nov 11, 2022 12:47 pm
by Benj
Hi Bruno,

First I would do a 1 second flasher test just to confirm you are running at the top speed of 64MHz. It could be the device is running slower then you think.

If the device is running at the right speed then what rate is the master sending out the SPI, could this be slowed down?

I have developed a SPI slave device and remember having similar problems, I may have ended up having to add small delays between the bytes sent by the master to allow the slave to keep up.

Re: SPI module as a slave

Posted: Fri Nov 11, 2022 8:13 pm
by Bruno
Hi Benj
Thank you for your support.
I checked the frequency of the micro and it is correct: I try to put some delays between the data sending macros, as you suggested.
Is there a better way to read the data than I did?
I tried to make a connection between two micro in I2C, one as master and one as slave, and everything works fine. Instead in SPI, when I start the micro, the bytes I receive on the slave are not always in the position where the master sends them.

best regards