完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include "SPI.h"
#include "cy_project.h" #define SCB_CH_TO_BE_USED SCB0 //#define SCB_CLOCK PCLK_SCB0_CLOCK #define SCB_INTERRUPT_NO scb_0_interrupt_IRQn ///* User setting value */ //#if (CY_USE_PSVP == 1) // #define SOURCE_CLOCK_FRQ 24000000ul //#else // #define SOURCE_CLOCK_FRQ 80000000ul //#endif //#define SCB_SPI_BAUDRATE 1000000ul /* Please set baudrate value of SPI you want */ #define SCB_SPI_OVERSAMPLING 16ul /* Please set oversampling of SPI you want */ //#define SCB_SPI_CLOCK_FREQ (SCB_SPI_BAUDRATE * SCB_SPI_OVERSAMPLING) #define DIVIDER_NO_1 (1u) cy_stc_scb_spi_context_t contextSCB; cy_stc_scb_spi_context_t contextSCB1; static cy_stc_sysint_irq_t irq_cfg = { .sysIntsrc=SCB_INTERRUPT_NO, .intIdx = CPUIntIdx3_IRQn, .isEnabled = true, }; static cy_stc_sysint_irq_t irq_cfg1 = { .sysIntsrc=scb_6_interrupt_IRQn, .intIdx = CPUIntIdx4_IRQn, // ?? .isEnabled = true, }; static const cy_stc_scb_spi_config_t SCB_SPI_cfg = { .spiMode = CY_SCB_SPI_MASTER, /*** Specifies the mode of operation ***/ .subMode = CY_SCB_SPI_MOTOROLA, /*** Specifies the submode of SPI operation ***/ .sclkMode = CY_SCB_SPI_CPHA0_CPOL0, /*** Clock is active low, data is changed on first edge ***/ .oversample = SCB_SPI_OVERSAMPLING, /*** SPI_CLOCK divided by SCB_SPI_OVERSAMPLING shoud be baudrate ***/ .rxDataWidth = 16, /*** The width of RX data (valid range 4-16). It must be the same as ref txDataWidth except in National sub-mode. ***/ .txDataWidth = 16, /*** The width of TX data (valid range 4-16). It must be the same as ref rxDataWidth except in National sub-mode. ***/ .enableMsbFirst = true, /*** Enables the hardware to shift out the data element MSB first, otherwise, LSB first ***/ .enableFreeRunSclk = false, /*** Enables the master to generate a continuous SCLK regardless of whether there is data to send ***/ .enableInputFilter = false, /*** Enables a digital 3-tap median filter to be applied to the input of the RX FIFO to filter glitches on the line. ***/ .enableMisoLateSample = true, /*** Enables the master to sample MISO line one half clock later to allow better timings. ***/ .enableTransferSeperation = true, /*** Enables the master to transmit each data element separated by a de-assertion of the slave select line (only applicable for the master mode) ***/ .ssPolarity0 = 0, /*** SS0: active low ***/ .ssPolarity1 = 0, /*** SS1: active low ***/ .ssPolarity2 = 0, /*** SS2: active low ***/ .ssPolarity3 = 0, /*** SS3: active low ***/ .enableWakeFromSleep = 0, /*** When set, the slave will wake the device when the slave select line becomes active. Note that not all SCBs support this mode. Consult the device datasheet to determine which SCBs support wake from deep sleep. ***/ // In case of using high level APIs, an user does not need to set these parameter. These parameter will be set in high level APIs such as "Cy_SCB_SPI_Transfer". .txFifoTriggerLevel = 0, /*** When there are fewer entries in the TX FIFO, then at this level the TX trigger output goes high. This output can be connected to a DMA channel through a trigger mux. Also, it controls the ref CY_SCB_SPI_TX_TRIGGER interrupt source. ***/ .rxFifoTriggerLevel = 255, /*** When there are more entries in the RX FIFO, then at this level the RX trigger output goes high. This output can be connected to a DMA channel through a trigger mux. Also, it controls the ref CY_SCB_SPI_RX_TRIGGER interrupt source. ***/ .rxFifoIntEnableMask = 0, /*** Bits set in this mask will allow events to cause an interrupt ***/ .txFifoIntEnableMask = 0, /*** Bits set in this mask allow events to cause an interrupt ***/ .masterSlaveIntEnableMask = 0, /*** Bits set in this mask allow events to cause an interrupt ***/ .enableSpiDoneInterrupt = 0, .enableSpiBusErrorInterrupt = 0, }; //#define SPI_SCB_1 void irqSCB(void) { Cy_SCB_SPI_Interrupt(SCB_CH_TO_BE_USED, contextSCB); } void irqSCB1(void) { Cy_SCB_SPI_Interrupt(SCB6, contextSCB1); } void SPI_Init(void) { Cy_SCB_SPI_Init(SCB_CH_TO_BE_USED, SCB_SPI_cfg, contextSCB); Cy_SCB_SPI_SetActiveSlaveSelect(SCB_CH_TO_BE_USED, 0); Cy_SCB_SPI_Enable(SCB_CH_TO_BE_USED); //#ifdef SPI_SCB_1 Cy_SCB_SPI_Init(SCB6, SCB_SPI_cfg, contextSCB1); Cy_SCB_SPI_SetActiveSlaveSelect(SCB6, 0); Cy_SCB_SPI_Enable(SCB6); //#endif } void SPI_DeInit(void) { Cy_SCB_SPI_DeInit(SCB_CH_TO_BE_USED); //#ifdef SPI_SCB_1 Cy_SCB_SPI_DeInit(SCB6); //#endif } void SPI_EnableSCBIrq(void) { Cy_SysInt_InitIRQ( irq_cfg); Cy_SysInt_SetSystemIrqVector(irq_cfg.sysIntSrc, irqSCB); NVIC_EnableIRQ(irq_cfg.intIdx); //#ifdef SPI_SCB_1 Cy_SysInt_InitIRQ( irq_cfg1); Cy_SysInt_SetSystemIrqVector(irq_cfg1.sysIntSrc, irqSCB1); NVIC_EnableIRQ(irq_cfg1.intIdx); //#endif } void SPI_SendData(uint8_t lu8_SCBChannel, void *txBuf, uint32_t size) { uint32_t transferStatus = 0u; if (lu8_SCBChannel == SPI_SBC_0) { Cy_SCB_SPI_Transfer(SCB_CH_TO_BE_USED, txBuf, NULL, size, contextSCB); do { transferStatus = Cy_SCB_SPI_GetTransferStatus(SCB_CH_TO_BE_USED, contextSCB); } while((transferStatus CY_SCB_SPI_TRANSFER_ACTIVE) != 0u); } else if (lu8_SCBChannel == SPI_SBC_1) { //#ifdef SPI_SCB_1 Cy_SCB_SPI_Transfer(SCB6, txBuf, NULL, size, contextSCB1); do { transferStatus = Cy_SCB_SPI_GetTransferStatus(SCB6, contextSCB1); } while((transferStatus CY_SCB_SPI_TRANSFER_ACTIVE) != 0u); //#endif } else { // MISRA C } } 大佬们,请帮忙看看。初始化后发送数据卡在do循环里面。Pin脚是port22的0~3。 |
|
相关推荐
1个回答
|
|
可能的原因包括:
1. SCB_CH_TO_BE_USED定义错误:请确保SCB_CH_TO_BE_USED定义的值正确,以指定要使用的SCB通道。 2. SCB_CLOCK定义错误:请确保SCB_CLOCK定义的值正确,并且与实际硬件配置的SCB时钟一致。 3. SCB_INTERRUPT_NO定义错误:请确保SCB_INTERRUPT_NO定义的值正确,并且与实际硬件配置的SCB中断号一致。 4. 注释掉的代码:请确保注释掉的代码没有影响到SPI1的使能。如果需要使用注释掉的代码,请确保其正确配置,并且与SPI1的相关设置兼容。 5. SOURCE_CLOCK_FRQ定义错误:请确保SOURCE_CLOCK_FRQ定义的值正确,并且与实际的时钟频率一致。 6. SCB_SPI_BAUDRATE定义错误:请确保SCB_SPI_BAUDRATE定义的值正确,并且与实际的SPI波特率一致。 7. SCB_SPI_OVERS定义错误:请确保SCB_SPI_OVERS定义的值正确,并且与实际的SPI时钟分频值一致。 请仔细检查以上代码和定义,并确保正确配置SPI1的使能。如果仍然无法使能SPI1,请提供更多相关代码和错误信息以便进一步分析和帮助。 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
298 浏览 1 评论
《DNESP32S3使用指南-IDF版_V1.6》第二十六章 INFRARED_RECEPTION实验
309 浏览 0 评论
826 浏览 0 评论
求助一下关于51系列单片机的Timer0的计时问题,TH0、TL0+1的时间是怎么算的?
1911 浏览 2 评论
【RA-Eco-RA4E2-64PIN-V1.0开发板试用】开箱+Keil环境搭建+点灯+点亮OLED
1427 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
12031 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 22:01 , Processed in 0.693152 second(s), Total 75, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号