2017-08-28 01:24 AM
Good afternoon~everybody
I use STM8S103 to be the Slave device of SPI. However, I don
’
t know why all the interrupt of STM8 received is 0*1 instead of the right data? This is the
http://www.kynix.com/uploadfiles/pdf8798/STM8S103F2P3.pdf
and the code is as following:[code]void spi_slave_init()
{
//NSS
GPIOA->DDR &= ~SPI_SSEL_PIN; //input pattern
GPIOA->CR1 &= ~SPI_SSEL_PIN; //Floated input
GPIOA->ODR &= (uint8_t)~SPI_SSEL_PIN; //write low
GPIOC->DDR |= SPI_MISO_PIN; //
out
put pattern
GPIOC->CR1 |= SPI_MISO_PIN; //
Push-pull output
GPIOC->DDR &= ~SPI_MOSI_PIN; //
input pattern
GPIOC->CR1 &= ~SPI_MOSI_PIN; //
Floated input
GPIOC->DDR &= ~SPI_CLK_PIN; //
input pattern
GPIOC->CR1 &= ~SPI_CLK_PIN; //
Floated input
SPI_DeInit();
// Initialize SPI in Slave mode, NSS hardwere management */
SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_2, SPI_MODE_SLAVE, SPI_CLOCKPOLARITY_HIGH,
SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_SOFT,(uint8_t)0x07);
SPI_ITConfig(SPI_IT_RXNE, ENABLE);// Receive buffer not empty interrupt Enable
SPI_Cmd(ENABLE); // SPI enable
}
uint8_t spi_rw(uint8_t byte)
{
char ch = 0;
while (SPI_GetFlagStatus(SPI_FLAG_TXE) == RESET);
SPI->DR = byte;
while(SPI_GetFlagStatus(SPI_FLAG_RXNE) == RESET);
ch = ((uint8_t)SPI->DR);
return ch;
}
INTERRUPT_HANDLER(SPI_IRQHandler, 10)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
uint8_t Rx_byte;
Rx_byte = spi_rw(0x18);
printf('%x ', Rx_byte)
:
}[/code[
Could anyboby here help me ? Thanks every much!