-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPI communication doesn't work #25
Comments
Fixed with #23 |
@VersBinarii I believe that #23 doens't fix the issue. The actual fix is this: From: self.spi
.transfer(data, &[register])
.map_err(|e| Error::Bus(SPIError::SPI(e)))?; To: self.device
.transaction(|bus| {
bus.write(&[register])?;
bus.read(data)
}) Please reopen the issue, I'll prepare a new, updated PR that resolves conflicts. |
Have you tested it though? |
@VersBinarii Yup. I'll test it again on Wednesday just to be sure. For now I could try to explain why the current approach doesn't work. Look at impl of fn transfer(&mut self, buff: &mut [W], data: &[W]) -> Result<(), Self::Error> {
assert_eq!(data.len(), buff.len());
for (d, b) in data.iter().cloned().zip(buff.iter_mut()) {
nb::block!(<Self as FullDuplex<W>>::write(self, d))?;
*b = nb::block!(<Self as FullDuplex<W>>::read(self))?;
}
Ok(())
} Let's say we want to read 3 bytes from address let write = [0xb7];
let mut read = [0x00; 3];
spi.transfer(&write, &mut read) If we really want to use let write = [0xb7, 0x00, 0x00, 0x00];
let mut read = [0x00, 0x00, 0x00, 0x00];
spi.transfer(&write, &mut read);
let response = &read[1..]; HAL_SPI_TransmitReceive from the C HAL works exactly same. Note that I didn't use |
I see, you're correct. |
FYI, I connected everything today, but I'll finish the PR tomorrow :P |
This fixes VersBinarii#25. Any try to call the `init` function will fail with an `UnsupportedChip` error without this (using the defautl `sync` feature). Previous attempts were made to fix this (VersBinarii#28 and VersBinarii#38) but these where made before `embedded-hal` `1.0.0` and currently have conflicts preventing their merge (and can't directly be used in a project using `embedded-hal` `1.0.0` closes VersBinarii#28
The following code is not right, as it would require the data to be prepended with a dummy byte
Spitting the transfer would do the job:
The text was updated successfully, but these errors were encountered: