0

I have tested with mraa and spidev, both cannot receive continuous data. For example, when send some bytes and expect receiving data in slave device like [1,2,3,4,5,6,7,8,9], I may get some data like [1,1,2,4,5,6,8,8,9], and each time is different.

The code in Slave device:

int bytecount = 0;

SPI1->DR = tx_buff[0];

    
while(cs == 0) {
    if(SPI1->SR&0x1) {
        rx_buff[bytecount] = SPI1->DR;
        bytecount++;
        if(bytecount<TX_LEN) {
            SPI1->DR = tx_buff[bytecount];
        }
    }

}

The code in master device:

import mraa
s=mraa.Spi(0)
s.frequency(5000000)
tx=bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00')
print(tx)

The code using spidev is similar.

I hope the master device can get continuous data. Thank you!

  • Have you tried lower clock rates, let’s say 1kHz? And side note: do not use MRAA never ever — it’s a big hack that should not have existed. – 0andriy Jul 07 '23 at 08:08
  • Thank you for answering my question. Some information was not mentioned in question, which is the rate of slave device was set with 5kHz, because I was new in using SPI. I did try lower clock rates, and the result showed it would work well when set lower than 2kHz. I don't know why. – muronglindong Aug 05 '23 at 16:21
  • Replacing MRAA with something better (preferably in-kernel driver) will give you much much better results. – 0andriy Aug 05 '23 at 19:17
  • Sorry, I made a mistake. In fact the unit of the rate should be MHz. The same situation while using spidev. – muronglindong Aug 05 '23 at 21:29
  • Still that does not contradict with my previous comment. – 0andriy Aug 06 '23 at 00:29

0 Answers0