nrf-rs / nrf-hal

A Rust HAL for the nRF family of devices
Apache License 2.0
499 stars 139 forks source link

`transfer`ing a buffer of a single byte hits SPIM errata, causing 2 bytes to be clocked out #411

Open korken89 opened 1 year ago

korken89 commented 1 year ago

Hi,

When doing the following one hits errata 58 in https://infocenter.nordicsemi.com/pdf/nRF52832_Rev_3_Errata_v1.1.pdf which causes the chip to clock out 2 bytes instead of only one. Plus the CS line goes high while clocking causing weird things to happen on the bus.

The issues happen when RXD.MAXCNT = 1 and TXD.MAXCNT <= 1, which the code below hits. I'm not sure how to best fix it. Setting RXD.MAXCNT = 0 for 1 byte transactions fixes the issue but you also do not read a byte then, and some chips do send their status byte in every transaction during the first byte being sent - this would break this kind of status byte reading.

Code:

let mut buf = [Opcode::WriteEnable as u8];
spi.transfer(&mut cs, &mut buf).ok();

Trace:

image