AnsweredAssumed Answered

K10 Spi read buffer bit inverted

Question asked by Nicola Orlandini on Feb 20, 2014
Latest reply on Feb 24, 2014 by jeremyzhou

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

Outcomes