有谁写过基于m4的NRF24l01的程序吗?我想看看我的哪里错了。[img=0,1]file:///C:UsersAdministratorAppDataRoamingTencentUsers1269148997QQWinTempRichOlePV}CYPAPAC$_N4%
VF@6KMGP.png[/img][img=0,1]file:///C:UsersAdministratorAppDataRoamingTencentUsers1269148997QQWinTempRichOlePV}CYPAPAC$_N4%
VF@6KMGP.png[/img][img=0,1]file:///C:UsersAdministratorAppDataRoamingTencentUsers1269148997QQWinTempRichOlePV}CYPAPAC$_N4%
VF@6KMGP.png[/img][img=0,1]file:///C:UsersAdministratorAppDataRoamingTencentUsers1269148997QQWinTempRichOlePV}CYPAPAC$_N4%
VF@6KMGP.png[/img][img=0,1]file:///C:UsersAdministratorAppDataRoamingTencentUsers1269148997QQWinTempRichOlePV}CYPAPAC$_N4%
VF@6KMGP.png[/img][img=0,1]file:///C:UsersAdministratorAppDataRoamingTencentUsers1269148997QQWinTempRichOlePV}CYPAPAC$_N4%
VF@6KMGP.png[/img][img=0,1]file:///C:UsersAdministratorAppDataRoamingTencentUsers1269148997QQWinTempRichOlePV}CYPAPAC$_N4%
VF@6KMGP.png[/img]
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);//40mhz
UART0_INIT();
NRF24L01_Init();
UARTprintf("TEST!");
while(1)
{
NRF24L01_Read_Reg(EN_RXADDR);
delay_ms(500);
}
}
void NRF24L01_Init(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_3);//SPI0_CS
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_6);//24L01_CE
GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_7);//24L01_IRQ
GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_7,0);//
GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_6,0);//ê1Äü24L01
SSI0_INIT();
// GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0xff);//è¡ÏûSSIƬѡ
}
u8 NRF24L01_Read_Reg(u8 reg)
{
u8 reg_val,status;
GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0);//ê1ÄüSPI′«êä
status=SPI0_ReadWriteByte(reg); //·¢Ëí¼Ä′æÆ÷oÅ
UARTprintf("s2:%d
",status);
reg_val=SPI0_ReadWriteByte(0XFF);//¶á衼Ä′æÆ÷ÄúèY
UARTprintf("r2:%d
",reg_val);
GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0xff);//½ûÖ1SPI′«êä
return(reg_val); //·μ»Ø×′ì¬Öμ
}
u8 SPI0_ReadWriteByte(u32 TxData)
{
u8 retry;
u32 SSI_Rec;
while(SSIBusy(SSI0_BASE))
{
retry++;
if(retry>200)
{
UARTprintf("fail1");
return 0;
}
}
SSIDataPut(SSI0_BASE, TxData);
UARTprintf("t:%d
",TxData);
retry=0;
while(SSIBusy(SSI0_BASE))
{
retry++;
if(retry>200)
{
UARTprintf("fail2");
return 0;
}
}
SSIDataGet(SSI0_BASE,&SSI_Rec);
UARTprintf("i:%d
",SSI_Rec);
return SSI_Rec;
}
此帖出自
小平头技术问答
一周热门 更多>