Open mcopela opened 4 years ago
I think we may be operating the peripheral incorrectly. The manual states that specific bits in SPI_CR1
be adjusted only while not enabled (SPE
= 0). For example:
This is confirmed when inspecting SPI driver code from ChibiOS HAL:
/* SPI setup and enable.*/
spip->spi->CR1 &= ~SPI_CR1_SPE;
spip->spi->CR1 = spip->config->cr1 | SPI_CR1_MSTR | SPI_CR1_SSM |
SPI_CR1_SSI;
spip->spi->CR2 = spip->config->cr2 | SPI_CR2_SSOE | SPI_CR2_RXDMAEN |
SPI_CR2_TXDMAEN;
spip->spi->CR1 |= SPI_CR1_SPE;
What are you getting in _result
?
What are you getting in
_result
?
The _result
is the same as buffer
. If I swap _result
with buffer
in the print statement I get the same output. Thanks for the help.
I think we may be operating the peripheral incorrectly. The manual states that specific bits in
SPI_CR1
be adjusted only while not enabled (SPE
= 0). For example: ...
I downloaded the crate locally and implemented the change; I set the settings first, then set SPE=1. It didn't seem to fix my problem. I'll keep messing with the settings.
hprintln!("Changing CR1");
#[allow(unused)]
spi.cr1.write(|w| unsafe {
w.spe()
.clear_bit()
});
hprintln!("CR1: {}",spi.cr1.read().bits());
spi.cr1.write(|w| unsafe {
w.cpha()
.bit(mode.phase == Phase::CaptureOnSecondTransition)
.cpol()
.bit(mode.polarity == Polarity::IdleHigh)
.mstr()
.set_bit()
.br()
.bits(br)
.lsbfirst()
.clear_bit()
.ssm()
.set_bit()
.ssi()
.set_bit()
.rxonly()
.clear_bit()
.dff()
.clear_bit()
.bidimode()
.clear_bit()
.spe()
.clear_bit()
});
hprintln!("CR1: {}",spi.cr1.read().bits());
spi.cr1.write(|w| unsafe {
w.cpha()
.bit(mode.phase == Phase::CaptureOnSecondTransition)
.cpol()
.bit(mode.polarity == Polarity::IdleHigh)
.mstr()
.set_bit()
.br()
.bits(br)
.lsbfirst()
.clear_bit()
.ssm()
.set_bit()
.ssi()
.set_bit()
.rxonly()
.clear_bit()
.dff()
.clear_bit()
.bidimode()
.clear_bit()
.spe()
.set_bit()
});
hprintln!("CR1: {}",spi.cr1.read().bits());
Changing CR1
CR1: 0
CR1: 820
CR1: 884
Buffer After Transfer: 14,15
Sounds to me like you are hitting HW bug. Take look at the errata section 2.6.2.
The problem is basically speed of the SCK pin. Unless your SCK pin connection has capacitance higher than 30 pF, setting the SCK pin speed as High or Very High should mitigate the issue. (It worked for me).
I'm seeing a strange problem with the Full Duplex SPI library I can't figure out. Any help is appreciated!
The LSB on my reads usually comes back flipped even though my oscilloscope shows the slave output to be as expected. Only the MISO LSB is affected. This happens no matter what I'm reading or which slave device I connect.
I'm running code on a STM32L031 Evaluation Board. The example below is with a TI CC1200 as the slave.
Example
The master writes 0x3D two times. The slave returns 0x0F two times (As confirmed by the oscilloscope). The transfer function incorrectly returns 0x0E 0x0F
My Code:
Code Output:
Buffer After Transfer: 14,15
Oscilloscope Output:
Things I've Tried: