Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RC_Green Drown RC_RX
Revision 8:62cdaa369cfa, committed 2019-12-15
- Comitter:
- Ucial
- Date:
- Sun Dec 15 02:48:57 2019 +0000
- Parent:
- 7:fa987efaeecd
- Commit message:
- complish RX and TX
Changed in this revision
nRF24L01P.cpp | Show annotated file Show diff for this revision Revisions of this file |
nRF24L01P.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/nRF24L01P.cpp Sat Dec 14 11:56:11 2019 +0000 +++ b/nRF24L01P.cpp Sun Dec 15 02:48:57 2019 +0000 @@ -8,7 +8,6 @@ int Nrf_Erro=0; int ledtick; -void nRF24L01P::setTransferSize(int TransSize ){} void nRF24L01P::setRxAddress(int RxAdd) { @@ -67,7 +66,7 @@ void nRF24L01P::NRF24L01_Set_TX(void) { ce_=0; - nRF24L01P::NRF_Write_Reg(NRF_WRITE_REG + CONFIG,0x0E); + NRF_Write_Reg(NRF_WRITE_REG + CONFIG,0x0E); ce_=1; } void nRF24L01P::NRF24L01_Set_RX(void) @@ -78,9 +77,9 @@ } void nRF24L01P::NRF_Send_TX(uint8_t * tx_buf, uint8_t len) { - nRF24L01P::NRF24L01_Set_TX(); + NRF24L01_Set_TX(); ce_=0; - nRF24L01P::NRF_Write_Buf(WR_TX_PLOAD, tx_buf, len); + NRF_Write_Buf(WR_TX_PLOAD, tx_buf, len); ce_=1; wait_us(10); ledtick++; @@ -96,9 +95,9 @@ uint8_t tx_buff[32]; for(i=0;i<len;i++) tx_buff[i]=tx_buf[i]&0xFF; - nRF24L01P::NRF24L01_Set_TX(); + NRF24L01_Set_TX(); ce_=0; - nRF24L01P::NRF_Write_Buf(WR_TX_PLOAD, tx_buff, len); + NRF_Write_Buf(WR_TX_PLOAD, tx_buff, len); ce_=1; wait_us(10); ledtick++; @@ -146,6 +145,17 @@ wait_ms(100); } } + else + { + uint8_t ledt; + for(ledt=0;ledt<2;ledt++) + { + check_led=0; + wait_ms(500); + check_led=1; + wait_ms(500); + } + } } void nRF24L01P::NRF24L01_Init(uint8_t Chanal,uint8_t Mode) { @@ -170,49 +180,56 @@ NRF_Write_Reg(NRF_WRITE_REG + CONFIG,0x0E); else if(Mode==RX) NRF_Write_Reg(NRF_WRITE_REG + CONFIG,0x0F); - nIRQ_.mode(PullDown); - nIRQ_.rise(&nRF_Analysis); + ce_=1; } void nRF24L01P::NRF24L01_IRQ(void) { uint8_t status = NRF_Read_Reg(NRF_READ_REG + NRFRegSTATUS); - if(status & (1<<RX_DR))//½ÓÊÕÖÐ¶Ï + if(status & (1<<RX_DR))//RX中断 { - uint8_t rx_len = NRF_Read_Reg(R_RX_PL_WID);//ÊÕµ½Êý¾Ý³¤¶È + uint8_t rx_len = NRF_Read_Reg(R_RX_PL_WID); if(rx_len==32) { - NRF_Read_Buff(RD_RX_PLOAD,NRF24L01_RXDATA,rx_len);//¶ÁÈ¡½ÓÊÕFIFOÊý¾Ý + NRF_Read_Buff(RD_RX_PLOAD,NRF24L01_RXDATA,rx_len);//读取FIFO Nrf_Erro = 0; } else { - NRF_Write_Reg(FLUSH_RX,0xff);//Çå¿Õ½ÓÊÕ»º³åÇø + NRF_Write_Reg(FLUSH_RX,0xff);//清空RX缓存 } } - if(status & (1<<MAX_RT))//´ïµ½×î¶à´ÎÖØ·¢ÖÐ¶Ï + if(status & (1<<MAX_RT))//达到最大重发次数 { - if(status & (1<<TX_FULL))//TX FIFO Òç³ö + if(status & (1<<TX_FULL))//TX FIFO 溢出 { - NRF_Write_Reg(FLUSH_TX,0xff);//Çå¿Õ·¢ËÍ»º³åÇø + NRF_Write_Reg(FLUSH_TX,0xff);//清空发送缓存 } } -// if(status & (1<<TX_DS))//·¢ËÍÍê³É -// { - NRF24L01_Set_RX();//ÉèÖÃNrf2401Ϊ½ÓÊÕģʽ -// } - NRF_Write_Reg(NRF_WRITE_REG + NRFRegSTATUS, status);//Çå³ýÖжϱê־λ + NRF24L01_Set_RX(); + NRF_Write_Reg(NRF_WRITE_REG + NRFRegSTATUS, status); +} +void nRF24L01P::NRF24L01_Analyse(int* data) +{ + uint8_t i; + for(i=0;i<32;i++) + data[i]=NRF24L01_RXDATA[i]; } -void nRF24L01P::Nrf_Connect(void)//500HZ +void nRF24L01P::Nrf_Connect(int* data)//1KHZ { - Nrf_Erro++; - if(Nrf_Erro%50==0) + Nrf_Erro ++; + if(Nrf_Erro==1) + { + NRF24L01_Analyse(data); + } + if(Nrf_Erro%100==0) { NRF24L01_IRQ(); } - if(Nrf_Erro>=500) + if(Nrf_Erro>=1000) { Nrf_Erro = 1; + } }
--- a/nRF24L01P.h Sat Dec 14 11:56:11 2019 +0000 +++ b/nRF24L01P.h Sun Dec 15 02:48:57 2019 +0000 @@ -82,8 +82,9 @@ void setRxAddress(int RxAdd); void setTxAddress(int TxAdd); - void Nrf_Connect(void); - + void Nrf_Connect(int* data); + void NRF24L01_Analyse(int* data); + SPI spi_; DigitalOut nCS_; DigitalOut ce_;