TI论坛
直播中

刘鑫

7年用户 168经验值
私信 关注
[问答]

发射模块返回的状态寄存器STATUS值一直为0x07是为什么?

因为对SPI的控制这方面的资料比较少,所以不知道这么做对不对。发射模块返回的状态寄存器STATUS值一直为0x07,按照附件的调试方法,返回的应该是0x2e。我想问一下关于SPI的使用有没有问题,代码如下。
#include #include #include "inc/tm4c123gh6pm.h"#include "inc/hw_memmap.h"#include "inc/hw_types.h"#include "inc/hw_ssi.h"#include "driverlib/ssi.h"#include "driverlib/pin_map.h"#include "driverlib/rom.h"#include "driverlib/rom_map.h"#include "driverlib/sysctl.h"#include "driverlib/gpio.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]=[0xfe,0xfd,0xfb,0xf7];uint8_t statusx;//*********************************************************************//SPI initialization,配置TM4C123GH6PM的SPI硬件void SPI_TM4C123_init(void)[        SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);        GPIOPinConfigure(GPIO_PA2_SSI0CLK);        GPIOPinConfigure(GPIO_PA3_SSI0FSS);        GPIOPinConfigure(GPIO_PA4_SSI0RX);        GPIOPinConfigure(GPIO_PA5_SSI0TX);        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,SSI_CR0_DSS_8);                        SSIEnable(SSI0_BASE);        ROM_SysCtlDelay(10000);] //******************************************************************** //用SPI配置nrf24l01的寄存器函数uint8_t SPI_Write_register(uint8_t WriteReg,uint8_t Value)//WriteReg要写的寄存器地址,Value要写的寄存器值[        uint32_t ui32Data;        uint8_t ui8Data;        SSIDataPut(SSI0_BASE, WriteReg);        SSIDataGet(SSI0_BASE, &ui32Data);        SSIDataPut(SSI0_BASE, Value);        SSIDataGet(SSI0_BASE, &ui32Data);        while (SSIBusy(SSI0_BASE))[]    ui8Data = ui32Data & 0xff;    return(ui8Data);]//**********************************************************************uint8_t SPI_Write_Buf(uint8_t WriteReg, uint8_t *pBuf, uint8_t bytes)[        uint8_t i,ui8Data;        uint32_t ui32Data;          SSIDataPut(SSI0_BASE,WriteReg);    // Select register to write to and read status byte          SSIDataGet(SSI0_BASE, &ui32Data);          for(i=0; i 我在TI的英文支持版块找到这个参考,一定要像它这样写吗
http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/349051
另外一个参考是来自TIVAWARE的SPI_flash.c



回帖(18)

韦明

2020-8-27 07:05:17
在这里下载TM4C129的参考例程
https://github.com/coon42/NRF24L01P
举报

刘鑫

2020-8-27 07:22:45
引用: ljmlvmd 发表于 2020-8-27 07:05
在这里下载TM4C129的参考例程
https://github.com/coon42/NRF24L01P

多谢
举报

刘鑫

2020-8-27 07:30:53
//*********************************************************************//* 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已经满足时序,其实没有。
举报

马知一

2020-8-27 07:49:34
谢谢楼主分享,楼主好人
举报

更多回帖

发帖
×
20
完善资料,
赚取积分