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,不知道什么原因啊,但是SPI Master可以收到stm8发送的0x18
{
//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,不知道什么原因啊,但是SPI Master可以收到stm8发送的0x18
你这个函数干嘛呀?
先发送后接受,改成单独的发送或接受试下;
SPI_ITConfig(SPI_IT_RXNE, ENABLE)后,有·这个SPI_FLAG_RXNE会产生一个RXNE中断
如果没有TX,就不要使用(SPI_GetFlagStatus(SPI_FLAG_TXE)
参考如下代码,
spi_interrupt(){
u8 irq_status = SPI->SR;
if(irq_status & SPI_SR_RXNE){// && (SPI->ICR & SPI_ICR_RXEI)){
p_context->rx[0] = SPI->DR;//// 读DR会自动清SR的RXNE标志
...
}
}
问:你在旅途中曾遇到过哪些厉害的人或事?
回复:我妈,她哪也不让我去。
一周热门 更多>