transfer16() does not work and "crashes".
the current code is:
The description says:
I'm not sure what " the SPIx_S register must be read with SPTEF = 1, " means, but changing it to
sems to help. But maybe we need to wait for SPTFEF with the "//while..." lines to be sure?
Frank
the current code is:
Code:
inline static uint8_t transfer16(uint16_t data) {
SPI0_C2 = SPI_C2_SPIMODE;
SPI0_DH = data >> 8;
SPI0_DL = data;
while (!(SPI0_S & SPI_S_SPRF)) ; // wait
uint16_t r = (SPI0_DH << 8) | SPI0_DL;
SPI0_C2 = 0;
return r;
}
Any switching between 8- and 16-bit data transmission length (controlled by SPIMODE
bit) in master mode will abort a transmission in progress, force the SPI system into idle
state, and reset all status bits in the SPIx_S register. To initiate a transfer after writing to
SPIMODE, the SPIx_S register must be read with SPTEF = 1, and data must be written
to SPIx_DH:SPIx_DL in 16-bit mode (SPIMODE = 1) or SPIx_DL in 8-bit mode
(SPIMODE = 0).
I'm not sure what " the SPIx_S register must be read with SPTEF = 1, " means, but changing it to
Code:
inline static uint8_t transfer16(uint16_t data) {
SPI0_C2 = SPI_C2_SPIMODE;
[B][I] SPI0_S ;
//while (!(SPI0_S & SPI_S_SPTEF)) ; // wait[/I][/B]
SPI0_DH = data >> 8;
SPI0_DL = data;
while (!(SPI0_S & SPI_S_SPRF)) ; // wait
uint16_t r = (SPI0_DH << 8) | SPI0_DL;
SPI0_C2 = 0;
[B][I] SPI0_S;
//while (!(SPI0_S & SPI_S_SPTEF)) ; // wait [/I][/B]
return r;
}
sems to help. But maybe we need to wait for SPTFEF with the "//while..." lines to be sure?
Frank
Last edited: