各路英雄好,我全用stm32f030c8t6不久,现需要它只接收arm9的spi数据即可,arm9这边的是用了很多年的系统,使用spi 400Khz CPOL=0, CPHA=0的方式往外发近100字节的连续数据。使用逻辑分析仪抓的波形比较好,但现在我使用c8t6的SPI2做从机, 中断中收到后打印的全是0, 希望有经验的GGJJ指点一下,在此谢过了!! 如下为初始化代码,是参考的官方例程STM32F0xx_StdPeriph_Lib_V1.3.1\Projects\STM32F0xx_StdPeriph_Examples\SPI\SPI_TwoBoards\DataExchangeInterrupt这里面的代码,而且我再三确认过ARM9 CS--> 030 CS ARM9 MOSI---> 030 MOSI ARM9 sck ---> 030 SCK static void SPI2_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* Enable the SPI periph */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); /* Enable SCK, MOSI, MISO and NSS GPIO clocks */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_0); GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_0); GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_0); //GPIO_PinAFConfig(RCC_AHBPeriph_GPIOA, SPIx_MISO_SOURCE, SPIx_MISO_AF); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /* SPI CS pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_Init(GPIOB, &GPIO_InitStructure); /* SPI SCK pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_Init(GPIOB, &GPIO_InitStructure); /* SPI MOSI pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_Init(GPIOB, &GPIO_InitStructure); /* SPI MISO ---> A0 Input GPIO configuration */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; GPIO_Init(GPIOB, &GPIO_InitStructure); RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE); RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE); /* SPI configuration -------------------------------------------------------*/ SPI_I2S_DeInit(SPI2); //SPI_Cmd(SPI2, DISABLE); SPI_InitStructure.SPI_Mode = SPI_Mode_Slave; SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;//SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI2, &SPI_InitStructure); /* Configure the SPI interrupt priority */ NVIC_InitStructure.NVIC_IRQChannel = SPI2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Initialize the FIFO threshold */ SPI_RxFIFOThresholdConfig(SPI2, SPI_RxFIFOThreshold_QF); /* Enable the Rx buffer not empty interrupt */ SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, ENABLE); /* Enable the SPI Error interrupt */ SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_ERR, ENABLE); /* Enable the SPI peripheral */ SPI_Cmd(SPI2, ENABLE); } void SPI2_IRQHandler(void) { //#if defined (SPI_SLAVE) #if 1 #if 0 /* SPI in Slave Tramitter mode--------------------------------------- */ if (SPI_I2S_GetITStatus(SPI2, SPI_I2S_IT_TXE) == SET) { SPI_SendData8(SPI2, TxBuffer[Tx_Idx++]); if (Tx_Idx == GetVar_NbrOfData()) { /* Disable the Tx buffer empty interrupt */ SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_TXE, DISABLE); } } #endif /* SPI in Slave Receiver mode--------------------------------------- */ while(SPI_I2S_GetITStatus(SPI2, SPI_I2S_IT_RXNE) == SET) { RxChr = SPI_ReceiveData8(SPI2); printf("%02x ", RxChr); RxBuffer[Rx_Idx++] = RxChr; if(Rx_Idx==64) Rx_Idx = 0; } #if 1 /* SPI Error interrupt--------------------------------------- */ if (SPI_I2S_GetITStatus(SPI2, SPI_I2S_IT_OVR) == SET) { SPI_ReceiveData8(SPI2); SPI_I2S_GetITStatus(SPI2, SPI_I2S_IT_OVR); printf("OV "); } #endif #if 1 /* SPI Error interrupt--------------------------------------- */ if (SPI_I2S_GetITStatus(SPI2, SPI_I2S_IT_FRE) == SET) { SPI_ReceiveData8(SPI2); SPI_I2S_GetITStatus(SPI2, SPI_I2S_IT_FRE); printf("FE "); } #endif #endif /* SPI_SLAVE*/ 在线等待啊, |
附上spi波形,
|
在中断中加断点,看一下RxChr的值是多少。 |
啊,大侠们都去哪里了,过来瞧瞧啊 |
嗯,查看过了 RxChr还真是0,本来是直接读到数组里面的,全0,读到字节变量里面,还是有问题 |
版主,代码部分对不对?? |
再发2张寄存器的图: |
自发自收试一下 |
结贴,嗯,代码绝对没问题,是硬件工程师搞错了线,感谢大伙 |
STM32F107+LWIP---如何检查tcp通讯断开?并重新连接
有没有用过数字式mems麦克风的,想问下SPI通讯的问题
stm32f103 CAN通讯多帧发送问题?
STM32F107作为USB主机模拟串口通讯不成功(采用PL2303芯片)
STM32F103C8 LIN通讯例程
求助,丐版J-Link通讯不上
ethernet可以与ethercat通讯吗?
LIS3DH SPI 通讯问题
STM32F373 CAN通讯问题CAN_FLAG_LEC
请教高手看看,STM32F1的多机通讯,地址匹配唤醒问题