Why the received SPI data is not continuous when using Python?

96 Views Asked by At

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!

0

There are 0 best solutions below