QUERY · ISSUE
pyboard: SPI slave, how to collect all data till an inter frame gap
port-stm32
I have a question about the SPI.recv() method, when used as SPI slave.
/// \method recv(recv, *, timeout=5000)
///
/// Receive data on the bus:
///
/// - `recv` can be an integer, which is the number of bytes to receive,
/// or a mutable buffer, which will be filled with received bytes.
/// - `timeout` is the timeout in milliseconds to wait for the receive.
///
/// Return value: if `recv` is an integer then a new buffer of the bytes received,
/// otherwise the same buffer that was passed in to `recv`.
STATIC mp_obj_t pyb_spi_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
Is it possible get all data received till the timeout occured?
Use case: I have a periodic transmission. The length of the frames vary. The inter frame gap is used to determine the end of a frame. I would like to collect all data till the timeout occurs.
Can I use the timeout parameter somehow for this purpose?
CANDIDATE · ISSUE
A SERVERE BUG OF SPI-SLAVE IN PYB
port-stm32
Hi Everybody:
There is a servere problem in pyb.SPI module, this problem occur when using the SPI.SLAVE mode:
Problem one:
1. SPI Master send 8 bytes buf = b'12345678' to pyboard which is working in SPI.SLAVE.
2. If we use SPI Slave receive 4 bytes, then we receive b'1234', the SPI Slave is in working order. However, if you send the 8 bytes and receive 4 bytes again, you will receive b'5123'. Try again, you will receive b'4123', then it will always be b'4123'.
3. This problem can be solved by two ways: A. keep the number of receive bytes equal to the send bytes. B. Use spi.init(****) before receive, and spi.deinit() after receive.
The Reason of This Bug:
I guess SPI Slave receive an extra bytes and and storage all received bytes in hardward register, for instance, if you use SPI Slave receive 4 bytes at the first time, it will receive 4 bytes (b'1234') and the extra bytes is b'5', it return first 4 bytes(b'1234') to you. Repeat this process again, it will still receive b'1234' but it return the extra bytes b'5'+b'123', thus it return you b'5123'(the last bytes b'4' will be leave in the extra bytes). Repeat this process again, it will receive b'1234' and return the extra bytes b'4' + b'123', the last bytes b'4' will be storage in the extra bytes. Repeat this process again, you still receive b'1234', and if you change the send bytes to b'abcdefgh', you will receive b'4abc', then to b'dabc'.
Another problem is that, you can't use spi.recv with slave mode in the callback function of interrupt, it can't receive any information and collapse.