使用STM8S103作为SPI Slave设备,但是STM8中断里面收到的全是0x1,收不到正确的数据,STM8发送看起来是对的。求大神帮忙指点一下,下面是代码:
void spi_slave_init()
{
//NSS
GPIOA->DDR &= ~SPI_SSEL_PIN; //输入模式
GPIOA->CR1 &= ~SPI_SSEL_PIN; //浮空输入
GPIOA->ODR &= (uint8_t)~SPI_SSEL_PIN; //write low
GPIOC->DDR |= SPI_MISO_PIN; //输出模式
GPIOC->CR1 |= SPI_MISO_PIN; //推挽输出
GPIOC->DDR &= ~SPI_MOSI_PIN; //输入模式
GPIOC->CR1 &= ~SPI_MOSI_PIN; //浮空输入
GPIOC->DDR &= ~SPI_CLK_PIN; //输入模式
GPIOC->CR1 &= ~SPI_CLK_PIN; //浮空输入
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);
}
中断里面收到的打印全是0x1,不知道什么原因啊, |