完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
各路英雄好,我全用STM32f030c8t6不久,现需要它只接收arm9的spi数据即可,arm9这边的是用了很多年的系统,使用spi 400Khz CPOL=0, CPHA=0的方式往外发近100字节的连续数据。使用逻辑分析仪抓的波形比较好,但现在我使用c8t6的SPI2做从机, 中断中收到后打印的全是0, 希望有经验的GGJJ指点一下,在此谢过了!! 如下为初始化代码,是参考的官方例程STM32F0xx_StdPeriph_Lib_V1.3.1ProjectsSTM32F0xx_StdPeriph_ExamplesSPISPI_TwoBoardsDataExchangeInterrupt这里面的代码,而且我再三确认过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*/ 在线等待啊, |
|
相关推荐
9个回答
|
|
|
|
|
|
在中断中加断点,看一下RxChr的值是多少。
|
|
|
|
啊,大侠们都去哪里了,过来瞧瞧啊
|
|
|
|
嗯,查看过了 RxChr还真是0,本来是直接读到数组里面的,全0,读到字节变量里面,还是有问题
|
|
|
|
版主,代码部分对不对??
|
|
|
|
|
|
|
|
自发自收试一下
|
|
|
|
结贴,嗯,代码绝对没问题,是硬件工程师搞错了线,感谢大伙
|
|
|
|
MISO 应该接到MOSI 吧?
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
2183 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
2011 浏览 3 评论
4612 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
2154 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
2687 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-25 12:55 , Processed in 0.868655 second(s), Total 89, Slave 73 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号