2009-02-17 10:08 PM
About SPI problem
2011-05-17 06:02 AM
Dear all,
I've some problem with STM8a SPI using.I find that my Rx-Data lost its first 7-bit data,then my Tx-Data has its MSB lost. Following is the configuration & interrupt routine.Would someone give me some advice or example? Thanks for you all. - CPOL=1, SCK 1 when idle - CPHA=1, the second clk transition is the first data capture edge - MSB first - Full-duplex, software slave management, slave mode - rx interrupt enable void Spi_Init(void) { SPI_CR2 = 0x02; SPI_CR1 = 0x43; SPI_ICR = 0x40; SPI_DR = 0xaa; // Set a head data in SPI data buffer first } /* Rx interrupt service routine */ void Spi_ISR(void) { unsigned int spidata; if(!(SPI_SR & 0x01))return; spidata = SPI_DR; SPI_DR = 0xaa; } When debuged,oscilloscopes captured a data 0x90, but receivedspidata is 0x48; if oscilloscopes captured a data 0x11, received spidata is 0x88 ...................... I've tried for time & time,still no progress.2011-05-17 06:02 AM
Hi Floodever,
For better SPI communication : 1) The baudrate must be low for exemple Fmaster/128 2) The idle state of SCK must correspond to the polarity selected in the SPI_CR1 register (by pulling up SCK if CPOL=1 or pulling down SCK if CPOL=0). 3) the master must be enabled before the salve, because if the slave is enabled first and wait for SCK waveform, any noise in SCK line will be probably interpreted as data. 4) Make sure that wires between Master and Slave are very short. Best Regards Bassinux2011-05-17 06:02 AM
Hi,
I see that the data received is shifted by 3bits, so the problem is related to synchronal between master and slave You can follow the following configuration 1- Configure master 2- Configure slave 3- Enable slave 4- Enable master 5- Send data keep me informed Regars mozra