n"); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0); SPI_RW(reg); status=SPI_RW(0); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,GPIO_PIN_3); UARTprintf("'%x' ", status); return(status);]//***********************************************************************void nrf24l01init(void)[ GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,0); // 处于待机模式一,所以可以写寄存器 SPI_Write_register(FLUSH_TX,0x00); SPI_Write_register(WRITE_REG+EN_AA,0X00);//失能通道0自动应答,方便单独调试 SPI_Write_register(WRITE_REG+EN_RXADDR,0X00);//失能接受通道0,方便单独调试发送模块 SPI_Write_register(WRITE_REG+SETUP_RETR,0x00);//失能自动重发 SPI_Write_register(WRITE_REG + RF_CH, 0x02); // Select RF channel 40 SPI_Write_register(WRITE_REG +RX_PW_P0,RX_PLOAD_WIDTH); SPI_Write_register(WRITE_REG + RF_SETUP, 0x07); // TX_PWR:0dBm, Datarate:1Mbps, LNA:HCURR SPI_Write_register(WRITE_REG+STATUS,0xff); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,GPIO_PIN_6); SysCtlDelay(235);//]//*************************************************************************void nrf24l01TxMode(void)//参考功能使用文档设置[ GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,0); SPI_Write_Buf(WRITE_REG + TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH); // Writes TX_Address to nRF24L01 SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, RX_ADDRESS, RX_ADR_WIDTH); SPI_Write_register(FLUSH_TX,0x00); SPI_Write_Buf(WR_TX_PLOAD, TX_Buf, TX_PLOAD_WIDTH); // Writes dat SPI_Write_register(WRITE_REG + CONFIG, 0x0e); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,GPIO_PIN_6); SysCtlDelay(185);//10us多点 GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,0);]//***************************************************************************//检测是否发射成功,成功红色的灯闪一下void testTXWin(void)[ uint32_t ui32Loop; uint8_t status,FIFOStatus; status=SPIReadStatus(STATUS); FIFOStatus=SPIReadStatus(FIFO_STATUS); if(status==0x2e&&FIFOStatus==0x11)//红色灯亮 [ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_1); GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,GPIO_PIN_1); for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++)[] GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0); for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++)[] ]]//***************************************************************************int main(void)[ SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); InitConsole(); UARTprintf("SSI ->n"); UARTprintf(" Mode: SPIn"); UARTprintf(" Data: 8-bitnn"); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE,GPIO_PIN_6); GPIOPinTypeGPIOInput(GPIO_PORTA_BASE,GPIO_PIN_7); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,0); SPI_TM4C123_init(); nrf24l01init(); //进入一直发射状态 while(1) [ nrf24l01TxMode(); testTXWin(); SPI_Write_register(WRITE_REG+STATUS,0xff); ]]这个是调试成功的发射模块,没有管接收模块。调试方法见一楼附件。此前调试失败的原因,以为SSIData函数的Fnss已经满足时序,其实没有。
//*********************************************************************//* spi_nrf24l01.c//*********************************************************************#include #include #include "inc/hw_memmap.h"#include "driverlib/ssi.h"#include "driverlib/pin_map.h"#include "driverlib/sysctl.h"#include "driverlib/gpio.h"#include "driverlib/uart.h"#include "utils/uartstdio.h"#include "nrf24l01.h"#define SSI_BitRate 1000000// Define a static TX addressuint8_t TX_ADDRESS[TX_ADR_WIDTH] = [0x34,0x43,0x10,0x10,0x01];uint8_t RX_ADDRESS[RX_ADR_WIDTH] = [0x34,0x43,0x10,0x10,0x01];uint8_t TX_Buf[TX_PLOAD_WIDTH]=['s','p','i','s','t'];uint8_t RX_Buf[TX_PLOAD_WIDTH];//*********************************************************************//SPI initialization,配置TM4C123GH6PM的SPI硬件void SPI_TM4C123_init(void)[ uint32_t ui32Data; SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA2_SSI0CLK); GPIOPinConfigure(GPIO_PA3_SSI0FSS); GPIOPinConfigure(GPIO_PA4_SSI0RX); GPIOPinConfigure(GPIO_PA5_SSI0TX); SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5|GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_2); SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,SSI_MODE_MASTER,SSI_BitRate,8); SSIEnable(SSI0_BASE); while(SSIDataGetNonBlocking(SSI0_BASE, &ui32Data))[]]//*********************************************************************************//UART初始化void InitConsole(void)[ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioConfig(0, 115200, 16000000);]//**********************************************************************//uint8_t SPI_RW(uint8_t value)[ uint32_t ui32Data; uint8_t ui8Data; SSIDataPut(SSI0_BASE,value); while (SSIBusy(SSI0_BASE))[] SSIDataGet(SSI0_BASE, &ui32Data); ui8Data = ui32Data & 0xff; return(ui8Data);]//********************************************************************//用SPI配置nrf24l01的寄存器函数uint8_t SPI_Write_register(uint8_t WriteReg,uint8_t Value)//WriteReg要写的寄存器地址,Value要写的寄存器值[ UARTprintf("nSPI_Wreg ->n"); uint8_t status; SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE,GPIO_PIN_3); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0); status=SPI_RW(WriteReg); SPI_RW(Value); UARTprintf("'%x' ", status); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,GPIO_PIN_3); return(status);]//**********************************************************************uint8_t SPI_Write_Buf(uint8_t WriteReg, uint8_t *pBuf, uint8_t bytes)[ uint8_t i,status; UARTprintf("nSPI_WBuf ->n"); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0); status=SPI_RW(WriteReg); for(i=0; in"); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0); SPI_RW(reg); status=SPI_RW(0); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,GPIO_PIN_3); UARTprintf("'%x' ", status); return(status);]//***********************************************************************void nrf24l01init(void)[ GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,0); // 处于待机模式一,所以可以写寄存器 SPI_Write_register(FLUSH_TX,0x00); SPI_Write_register(WRITE_REG+EN_AA,0X00);//失能通道0自动应答,方便单独调试 SPI_Write_register(WRITE_REG+EN_RXADDR,0X00);//失能接受通道0,方便单独调试发送模块 SPI_Write_register(WRITE_REG+SETUP_RETR,0x00);//失能自动重发 SPI_Write_register(WRITE_REG + RF_CH, 0x02); // Select RF channel 40 SPI_Write_register(WRITE_REG +RX_PW_P0,RX_PLOAD_WIDTH); SPI_Write_register(WRITE_REG + RF_SETUP, 0x07); // TX_PWR:0dBm, Datarate:1Mbps, LNA:HCURR SPI_Write_register(WRITE_REG+STATUS,0xff); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,GPIO_PIN_6); SysCtlDelay(235);//]//*************************************************************************void nrf24l01TxMode(void)//参考功能使用文档设置[ GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,0); SPI_Write_Buf(WRITE_REG + TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH); // Writes TX_Address to nRF24L01 SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, RX_ADDRESS, RX_ADR_WIDTH); SPI_Write_register(FLUSH_TX,0x00); SPI_Write_Buf(WR_TX_PLOAD, TX_Buf, TX_PLOAD_WIDTH); // Writes dat SPI_Write_register(WRITE_REG + CONFIG, 0x0e); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,GPIO_PIN_6); SysCtlDelay(185);//10us多点 GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,0);]//***************************************************************************//检测是否发射成功,成功红色的灯闪一下void testTXWin(void)[ uint32_t ui32Loop; uint8_t status,FIFOStatus; status=SPIReadStatus(STATUS); FIFOStatus=SPIReadStatus(FIFO_STATUS); if(status==0x2e&&FIFOStatus==0x11)//红色灯亮 [ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_1); GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,GPIO_PIN_1); for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++)[] GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0); for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++)[] ]]//***************************************************************************int main(void)[ SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); InitConsole(); UARTprintf("SSI ->n"); UARTprintf(" Mode: SPIn"); UARTprintf(" Data: 8-bitnn"); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE,GPIO_PIN_6); GPIOPinTypeGPIOInput(GPIO_PORTA_BASE,GPIO_PIN_7); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,0); SPI_TM4C123_init(); nrf24l01init(); //进入一直发射状态 while(1) [ nrf24l01TxMode(); testTXWin(); SPI_Write_register(WRITE_REG+STATUS,0xff); ]]这个是调试成功的发射模块,没有管接收模块。调试方法见一楼附件。此前调试失败的原因,以为SSIData函数的Fnss已经满足时序,其实没有。
举报