Hi, I'm using a K10 as SPI master. I've some problem with rx buffer.
I'm trying to read data from MAX31855: data are storage, but MSB has been saved in bit 0 of rx_buffer. Do someone explain me why?
My code is the following:
/* Initialization SPI */
SIM_SCGC6 |= SIM_SCGC6_SPI0_MASK;
SPI_MCR_REG(regmap) = SPI_MCR_MSTR_MASK | SPI_MCR_CONT_SCKE_MASK | SPI_MCR_PCSIS(0xF) | SPI_MCR_HALT_MASK;
SPI_CTAR_REG(regmap,0) = SPI_CTAR_FMSZ(0x7) | SPI_CTAR_BR(0x05) | SPI_CTAR_CPHA_MASK | ~SPI_CTAR_CPOL_MASK;
SPI_CTAR_REG(regmap,1) = SPI_CTAR_FMSZ(0x7) | SPI_CTAR_BR(0x05) | SPI_CTAR_CPHA_MASK | ~SPI_CTAR_CPOL_MASK;
/* Main */
while((SPI_SR_REG(regmap) & SPI_SR_TFFF_MASK) != 0x2000000U);
// Transmit Byte on SPI
SPI_MCR_REG(regmap) &= ~SPI_MCR_HALT_MASK;
SPI_PUSHR_REG(regmap) |= 0xFFFF;
//--> Wait till transmit complete
while (((SPI_SR_REG(regmap) & SPI_SR_TCF_MASK)) != SPI_SR_TCF_MASK);
//--> Clear Transmit Flag.
SPI_SR_REG(regmap) |= SPI_SR_TFFF_MASK;
data = SPI_POPR_RXDATA(regmap);
Another problem that I have is that I want to send a 8bit per time, but it send and receive 16bit per time. Why? I have setted SPI_CTAR_FMSZ(0x7), but when I stop in debug mode, I read 0xF in FMSZ!
Can you help me?
Nicola
Hi Nicola,
I've had a brief through your code and I think your cod is not very right.
For instance, your code didn't select the CTAR0 or CTAR1 for clock and transfer attribute if use SPI_PUSHR_REG(regmap) |= 0xFFFF;
You also can't send a 8bit per time prorperly with this code.
So I've like to suggest a demo code about K60 connect with a exteranl flash chip through SPI interface.
I think it should be useful for reference and I've attached the file with the reply. Please refer to it for details.
Wish it help.
Best regards,
Ping