完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
这是接收程序,就是接收不到数据,求各位大神一看!!
#include "nrf24l01.h" #include "sys.h" #include "delay.h" #define uchar unsigned char #define uint unsigned int uchar TX_DATA[4]; uint8_t NRF24L01_RXDATA[RX_PLOAD_WIDTH];//nrf24l01½ÓÊÕµ½µÄÊý¾Ý uint8_t NRF24L01_TXDATA[RX_PLOAD_WIDTH];//nrf24l01ÐèÒª·¢Ë͵ÄÊý¾Ý u8 TX_ADDRESS[TX_ADR_WIDTH]= {0xE1,0xE2,0xE3,0xE4,0xE5}; //±¾µØµØÖ· u8 RX_ADDRESS[RX_ADR_WIDTH]= {0xE1,0xE2,0xE3,0xE4,0xE5}; //½ÓÊÕµØÖ· /* ***************************************************************** * д¼Ä´æÆ÷ ***************************************************************** */ uint8_t NRF_Write_Reg(uint8_t reg, uint8_t value) { uint8_t status; SPI_CSN_L(); /* ѡͨÆ÷¼þ */ status = Spi_RW(reg); /* д¼Ä´æÆ÷µØÖ· */ Spi_RW(value); /* дÊý¾Ý */ SPI_CSN_H(); /* ½ûÖ¹¸ÃÆ÷¼þ */ return status; } /* ***************************************************************** * ¶Á¼Ä´æÆ÷ ***************************************************************** */ uint8_t NRF_Read_Reg(uint8_t reg) { uint8_t reg_val; SPI_CSN_L(); /* ѡͨÆ÷¼þ */ Spi_RW(reg); /* д¼Ä´æÆ÷µØÖ· */ reg_val = Spi_RW(0); /* ¶ÁÈ¡¸Ã¼Ä´æÆ÷·µ»ØÊý¾Ý */ SPI_CSN_H(); /* ½ûÖ¹¸ÃÆ÷¼þ */ return reg_val; } /* ***************************************************************** * * д»º³åÇø * ***************************************************************** */ uint8_t NRF_Write_Buf(uint8_t reg, uint8_t *pBuf, uint8_t uchars) { uint8_t i; uint8_t status; SPI_CSN_L(); /* ѡͨÆ÷¼þ */ status = Spi_RW(reg); /* д¼Ä´æÆ÷µØÖ· */ for(i=0; i Spi_RW(pBuf[i]); /* дÊý¾Ý */ } SPI_CSN_H(); /* ½ûÖ¹¸ÃÆ÷¼þ */ return status; } /* ***************************************************************** * ¶Á»º³åÇø ***************************************************************** */ uint8_t NRF_Read_Buf(uint8_t reg, uint8_t *pBuf, uint8_t uchars) { uint8_t i; uint8_t status; SPI_CSN_L(); /* ѡͨÆ÷¼þ */ status = Spi_RW(reg); /* д¼Ä´æÆ÷µØÖ· */ for(i=0; i pBuf[i] = Spi_RW(0); /* ¶ÁÈ¡·µ»ØÊý¾Ý */ } SPI_CSN_H(); /* ½ûÖ¹¸ÃÆ÷¼þ */ return status; } /* ***************************************************************** * дÊý¾Ý°ü ***************************************************************** */ void NRF_TxPacket(uint8_t * tx_buf, uint8_t len) { SPI_CE_L(); //StandBy Iģʽ NRF_Write_Buf(WR_TX_PLOAD, tx_buf, len); // ×°ÔØÊý¾Ý SPI_CE_H(); //ÖøßCE£¬¼¤·¢Êý¾Ý·¢ËÍ } void NRF_TxPacket_AP(uint8_t * tx_buf, uint8_t len) { SPI_CE_L(); //StandBy Iģʽ NRF_Write_Buf(0xa8, tx_buf, len); // ×°ÔØÊý¾Ý SPI_CE_H(); //ÖøßCE } u8 Nrf24l01_Check(void) { u8 buf1[5]; u8 i; /*дÈë5¸ö×ֽڵĵØÖ·. */ NRF_Write_Buf(NRF_WRITE_REG+TX_ADDR,TX_ADDRESS,5); /*¶Á³öдÈëµÄµØÖ· */ NRF_Read_Buf(TX_ADDR,buf1,5); /*±È½Ï*/ for(i=0;i<5;i++) { if(buf1[i]!=TX_ADDRESS[i]) break; } if(i==5) return SUCCESS ; //MCUÓëNRF³É¹¦Á¬½Ó else return ERROR ; //MCUÓëNRF²»Õý³£Á¬½Ó } void Nrf24l01_Init(u8 model) { SPI_CE_L(); NRF_Write_Buf(NRF_WRITE_REG+RX_ADDR_P0,RX_ADDRESS,RX_ADR_WIDTH); //дRX½ÚµãµØÖ· NRF_Write_Buf(NRF_WRITE_REG+TX_ADDR,TX_ADDRESS,TX_ADR_WIDTH); //дTX½ÚµãµØÖ· NRF_Write_Reg(NRF_WRITE_REG+EN_AA,0x00); //ʹÄÜͨµÀ0µÄ×Ô¶¯Ó¦´ð NRF_Write_Reg(NRF_WRITE_REG+EN_RXADDR,0x01); //ʹÄÜͨµÀ0µÄ½ÓÊÕµØÖ· NRF_Write_Reg(NRF_WRITE_REG+SETUP_RETR,0x00); //ÉèÖÃ×Ô¶¯ÖØ·¢¼ä¸ôʱ¼ä:500us;×î´ó×Ô¶¯ÖØ·¢´ÎÊý:10´Î NRF_Write_Reg(NRF_WRITE_REG+RF_CH,40); //ÉèÖÃRFͨµÀΪCHANAL NRF_Write_Reg(NRF_WRITE_REG+RF_SETUP,0x0f); //ÉèÖÃTX·¢Éä²ÎÊý,0dbÔöÒæ,2Mbps,µÍÔëÉùÔöÒ濪Æô if(model==1) //RX { NRF_Write_Reg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //Ñ¡ÔñͨµÀ0µÄÓÐЧÊý¾Ý¿í¶È NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0f); // IRQÊÕ·¢Íê³ÉÖжϿªÆô,16λCRC,Ö÷½ÓÊÕ } else if(model==2) //TX { NRF_Write_Reg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //Ñ¡ÔñͨµÀ0µÄÓÐЧÊý¾Ý¿í¶È NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0e); // IRQÊÕ·¢Íê³ÉÖжϿªÆô,16λCRC,Ö÷·¢ËÍ } else if(model==3) //RX2 { NRF_Write_Reg(FLUSH_TX,0xff); NRF_Write_Reg(FLUSH_RX,0xff); NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0f); // IRQÊÕ·¢Íê³ÉÖжϿªÆô,16λCRC,Ö÷½ÓÊÕ Spi_RW(0x50); Spi_RW(0x73); NRF_Write_Reg(NRF_WRITE_REG+0x1c,0x01); NRF_Write_Reg(NRF_WRITE_REG+0x1d,0x06); } else //TX2 { NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0e); // IRQÊÕ·¢Íê³ÉÖжϿªÆô,16λCRC,Ö÷·¢ËÍ NRF_Write_Reg(FLUSH_TX,0xff); NRF_Write_Reg(FLUSH_RX,0xff); Spi_RW(0x50); Spi_RW(0x73); NRF_Write_Reg(NRF_WRITE_REG+0x1c,0x01); NRF_Write_Reg(NRF_WRITE_REG+0x1d,0x06); } SPI_CE_H(); } u8 NRF24L01_RxPacket(u8 *rxbuf) { u8 state,flag; state=NRF_Read_Reg(NRF_READ_REG+NRFRegSTATUS); NRF_Write_Reg(NRF_WRITE_REG+NRFRegSTATUS,state); if(NRFRegSTATUS&RX_DR) // ÅжÏÊÇ·ñ½ÓÊÕµ½Êý¾Ý { NRF_Read_Buf(RD_RX_PLOAD ,rxbuf,RX_PLOAD_WIDTH);// ´ÓRXFIFO¶ÁÈ¡Êý¾Ý ½ÓÊÕ4λ¼´¿É£¬ºóһλλ½áÊøλ NRF_Write_Reg(FLUSH_RX,0xff);//ÓÃÓÚÇå¿ÕFIFO £¡£¡¹Ø¼ü£¡£¡²»È»»á³öÏÖÒâÏë²»µ½µÄºó¹û£¡£¡£¡´ó¼Ò¼Çס£¡ flag=1; return flag; } } u8 rx_buf[32]; extern unsigned char TX_DATA[4]; u8 NRF_Get_State(void) { u8 status; status=NRF_Read_Reg(NRF_READ_REG + NRFRegSTATUS); return status; } u8 NRF_Get_FIFOState(void) { u8 FIFO_status; FIFO_status=NRF_Read_Reg(NRF_READ_REG + FIFO_STATUS); return FIFO_status; } int main() { u8 sta,Flag; u8 FIFO_sta; RCC_Init(); // ʱÖÓÅäÖà timer3_Init(); //¶¨Ê±Æ÷3³õʼ»¯ USART1_Init(); // USART1³õʼ»¯ Spi3_Init(); Nrf24l01_Init(MODEL_RX); GPIO_Config(); while(1) { NRF24L01_RxPacket(rx_buf); sta=NRF_Get_State(); FIFO_sta=NRF_Get_FIFOState(); if (sta==0x40 || Flag==NRF24L01_RxPacket(rx_buf)) { GPIO_SetBits(GPIOD, GPIO_Pin_13); Delay_ms(500); GPIO_ResetBits(GPIOD, GPIO_Pin_13); Delay_ms(500); } if(rx_buf[0]==2||rx_buf[1]==1||rx_buf[2]==15) { GPIO_ResetBits(GPIOG, GPIO_Pin_14); Delay_ms(500); GPIO_SetBits(GPIOG, GPIO_Pin_14); Delay_ms(500); } } } 下面是发送程序,statue的值为0x2e,fifostatus的值为0x11 #include "nrf24l01.h" #include "sys.h" #include "delay.h" #include "RCC_config.h" #define uchar unsigned char #define uint unsigned int uchar TX_DATA[4]; uint8_t NRF24L01_RXDATA[RX_PLOAD_WIDTH];//nrf24l01½ÓÊÕµ½µÄÊý¾Ý uint8_t NRF24L01_TXDATA[RX_PLOAD_WIDTH];//nrf24l01ÐèÒª·¢Ë͵ÄÊý¾Ý u8 TX_ADDRESS[TX_ADR_WIDTH]= {0xE1,0xE2,0xE3,0xE4,0xE5}; //±¾µØµØÖ· u8 RX_ADDRESS[RX_ADR_WIDTH]= {0xE1,0xE2,0xE3,0xE4,0xE5}; //½ÓÊÕµØÖ· /* ***************************************************************** * д¼Ä´æÆ÷ ***************************************************************** */ uint8_t NRF_Write_Reg(uint8_t reg, uint8_t value) { uint8_t status; SPI_CSN_L(); /* ѡͨÆ÷¼þ */ status = Spi_RW(reg); /* д¼Ä´æÆ÷µØÖ· */ Spi_RW(value); /* дÊý¾Ý */ SPI_CSN_H(); /* ½ûÖ¹¸ÃÆ÷¼þ */ return status; } /* ***************************************************************** * ¶Á¼Ä´æÆ÷ ***************************************************************** */ uint8_t NRF_Read_Reg(uint8_t reg) { uint8_t reg_val; SPI_CSN_L(); /* ѡͨÆ÷¼þ */ Spi_RW(reg); /* д¼Ä´æÆ÷µØÖ· */ reg_val = Spi_RW(0); /* ¶ÁÈ¡¸Ã¼Ä´æÆ÷·µ»ØÊý¾Ý */ SPI_CSN_H(); /* ½ûÖ¹¸ÃÆ÷¼þ */ return reg_val; } /* ***************************************************************** * * д»º³åÇø * ***************************************************************** */ uint8_t NRF_Write_Buf(uint8_t reg, uint8_t *pBuf, uint8_t uchars) { uint8_t i; uint8_t status; SPI_CSN_L(); /* ѡͨÆ÷¼þ */ status = Spi_RW(reg); /* д¼Ä´æÆ÷µØÖ· */ for(i=0; i Spi_RW(pBuf[i]); /* дÊý¾Ý */ } SPI_CSN_H(); /* ½ûÖ¹¸ÃÆ÷¼þ */ return status; } /* ***************************************************************** * ¶Á»º³åÇø ***************************************************************** */ uint8_t NRF_Read_Buf(uint8_t reg, uint8_t *pBuf, uint8_t uchars) { uint8_t i; uint8_t status; SPI_CSN_L(); /* ѡͨÆ÷¼þ */ status = Spi_RW(reg); /* д¼Ä´æÆ÷µØÖ· */ for(i=0; i pBuf[i] = Spi_RW(0); /* ¶ÁÈ¡·µ»ØÊý¾Ý */ } SPI_CSN_H(); /* ½ûÖ¹¸ÃÆ÷¼þ */ return status; } /* ***************************************************************** * дÊý¾Ý°ü ***************************************************************** */ void NRF_TxPacket(uint8_t * tx_buf, uint8_t len) { SPI_CE_L(); //StandBy Iģʽ NRF_Write_Buf(WR_TX_PLOAD, tx_buf, len); // ×°ÔØÊý¾Ý SPI_CE_H(); //ÖøßCE£¬¼¤·¢Êý¾Ý·¢ËÍ } void NRF_TxPacket_AP(uint8_t * tx_buf, uint8_t len) { SPI_CE_L(); //StandBy Iģʽ NRF_Write_Buf(0xa8, tx_buf, len); // ×°ÔØÊý¾Ý SPI_CE_H(); //ÖøßCE } u8 Nrf24l01_Check(void) { u8 buf1[5]; u8 i; /*дÈë5¸ö×ֽڵĵØÖ·. */ NRF_Write_Buf(NRF_WRITE_REG+TX_ADDR,TX_ADDRESS,5); /*¶Á³öдÈëµÄµØÖ· */ NRF_Read_Buf(TX_ADDR,buf1,5); /*±È½Ï*/ for(i=0;i<5;i++) { if(buf1[i]!=TX_ADDRESS[i]) break; } if(i==5) return SUCCESS ; //MCUÓëNRF³É¹¦Á¬½Ó else return ERROR ; //MCUÓëNRF²»Õý³£Á¬½Ó } void Nrf24l01_Init(u8 model) { SPI_CE_L(); NRF_Write_Buf(NRF_WRITE_REG+RX_ADDR_P0,TX_ADDRESS,RX_ADR_WIDTH); //дRX½ÚµãµØÖ· NRF_Write_Buf(NRF_WRITE_REG+TX_ADDR,TX_ADDRESS,TX_ADR_WIDTH); //дTX½ÚµãµØÖ· NRF_Write_Reg(NRF_WRITE_REG+EN_AA,0x00); //ʹÄÜͨµÀ0µÄ×Ô¶¯Ó¦´ð NRF_Write_Reg(NRF_WRITE_REG+EN_RXADDR,0x00); //ʹÄÜͨµÀ0µÄ½ÓÊÕµØÖ· NRF_Write_Reg(NRF_WRITE_REG+SETUP_RETR,0x00); //ÉèÖÃ×Ô¶¯ÖØ·¢¼ä¸ôʱ¼ä:500us;×î´ó×Ô¶¯ÖØ·¢´ÎÊý:10´Î NRF_Write_Reg(NRF_WRITE_REG+RF_CH,40); //ÉèÖÃRFͨµÀΪCHANAL NRF_Write_Reg(NRF_WRITE_REG+RF_SETUP,0x0f); //ÉèÖÃTX·¢Éä²ÎÊý,0dbÔöÒæ,2Mbps,µÍÔëÉùÔöÒ濪Æô if(model==1) //RX { NRF_Write_Reg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //Ñ¡ÔñͨµÀ0µÄÓÐЧÊý¾Ý¿í¶È NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0f); // IRQÊÕ·¢Íê³ÉÖжϿªÆô,16λCRC,Ö÷½ÓÊÕ } else if(model==2) //TX { NRF_Write_Reg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //Ñ¡ÔñͨµÀ0µÄÓÐЧÊý¾Ý¿í¶È NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0e); // IRQÊÕ·¢Íê³ÉÖжϿªÆô,16λCRC,Ö÷·¢ËÍ } else if(model==3) //RX2 { NRF_Write_Reg(FLUSH_TX,0xff); NRF_Write_Reg(FLUSH_RX,0xff); NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0f); // IRQÊÕ·¢Íê³ÉÖжϿªÆô,16λCRC,Ö÷½ÓÊÕ Spi_RW(0x50); Spi_RW(0x73); NRF_Write_Reg(NRF_WRITE_REG+0x1c,0x01); NRF_Write_Reg(NRF_WRITE_REG+0x1d,0x06); } else //TX2 { NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0e); // IRQÊÕ·¢Íê³ÉÖжϿªÆô,16λCRC,Ö÷·¢ËÍ NRF_Write_Reg(FLUSH_TX,0xff); NRF_Write_Reg(FLUSH_RX,0xff); Spi_RW(0x50); Spi_RW(0x73); NRF_Write_Reg(NRF_WRITE_REG+0x1c,0x01); NRF_Write_Reg(NRF_WRITE_REG+0x1d,0x06); } SPI_CE_H(); } u8 NRF24L01_RxPacket(u8 *rxbuf) { u8 state,flag; state=NRF_Read_Reg(NRF_READ_REG+NRFRegSTATUS); NRF_Write_Reg(NRF_WRITE_REG+NRFRegSTATUS,state); if(NRFRegSTATUS&RX_DR) // ÅжÏÊÇ·ñ½ÓÊÕµ½Êý¾Ý { NRF_Read_Buf(RD_RX_PLOAD ,rxbuf,RX_PLOAD_WIDTH);// ´ÓRXFIFO¶ÁÈ¡Êý¾Ý ½ÓÊÕ4λ¼´¿É£¬ºóһλλ½áÊøλ NRF_Write_Reg(FLUSH_RX,0xff);//ÓÃÓÚÇå¿ÕFIFO £¡£¡¹Ø¼ü£¡£¡²»È»»á³öÏÖÒâÏë²»µ½µÄºó¹û£¡£¡£¡´ó¼Ò¼Çס£¡ flag=1; return flag; } return 0; } u8 rx_buf[32]; u8 send[32]={2,1,15,3,6,4,7,8,9,0}; extern unsigned char TX_DATA[4]; u8 NRF_Get_State(void) { u8 status; status=NRF_Read_Reg(NRF_READ_REG + NRFRegSTATUS); return status; } u8 NRF_Get_FIFOState(void) { u8 FIFO_status; FIFO_status=NRF_Read_Reg(NRF_READ_REG + FIFO_STATUS); return FIFO_status; } int main() { u8 sta; u8 FIFO_sta; RCC_Init(); // ʱÖÓÅäÖà Timer3_Init(); //¶¨Ê±Æ÷3³õʼ»¯ USART1_Init(); // USART1³õʼ»¯ GPIO_Config(); Spi2_Init(); Nrf24l01_Init(MODEL_TX); while(1) { while (1) { if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == Bit_RESET) { NRF_TxPacket(send,10); GPIO_ResetBits(GPIOF, GPIO_Pin_7); /* µãÁÁLED0 */ Delay_ms(500); Delay_ms(500); break; } } while (1) { if ((GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == Bit_SET)) { GPIO_SetBits(GPIOF, GPIO_Pin_7); /* ¹Ø±ÕLED0 */ break; } } sta=NRF_Get_State(); FIFO_sta=NRF_Get_FIFOState(); if (sta==0x2e) { GPIO_ResetBits(GPIOF, GPIO_Pin_8); Delay_ms(500); GPIO_SetBits(GPIOF, GPIO_Pin_8); Delay_ms(500); GPIO_ResetBits(GPIOF, GPIO_Pin_9); Delay_ms(500); GPIO_SetBits(GPIOF, GPIO_Pin_9); Delay_ms(500); } if (FIFO_sta==0x11) { int i; for (i=0;i<100;i++) { GPIO_ResetBits(GPIOF, GPIO_Pin_6); Delay_ms(100); GPIO_SetBits(GPIOF, GPIO_Pin_6); Delay_ms(100); } } |
|
相关推荐
2个回答
|
|
这是后面的
uint8_t NRF_Write_Buf(uint8_t reg, uint8_t *pBuf, uint8_t uchars) { uint8_t i; uint8_t status; SPI_CSN_L(); /* ѡͨÆ÷¼þ */ status = Spi_RW(reg); /* д¼Ä´æÆ÷µØÖ· */ for(i=0; i Spi_RW(pBuf[i]); /* дÊý¾Ý */ } SPI_CSN_H(); /* ½ûÖ¹¸ÃÆ÷¼þ */ return status; } /* ***************************************************************** * ¶Á»º³åÇø ***************************************************************** */ uint8_t NRF_Read_Buf(uint8_t reg, uint8_t *pBuf, uint8_t uchars) { uint8_t i; uint8_t status; SPI_CSN_L(); /* ѡͨÆ÷¼þ */ status = Spi_RW(reg); /* д¼Ä´æÆ÷µØÖ· */ for(i=0; i pBuf[i] = Spi_RW(0); /* ¶ÁÈ¡·µ»ØÊý¾Ý */ } SPI_CSN_H(); /* ½ûÖ¹¸ÃÆ÷¼þ */ return status; } /* ***************************************************************** * дÊý¾Ý°ü ***************************************************************** */ void NRF_TxPacket(uint8_t * tx_buf, uint8_t len) { SPI_CE_L(); //StandBy Iģʽ NRF_Write_Buf(WR_TX_PLOAD, tx_buf, len); // ×°ÔØÊý¾Ý SPI_CE_H(); //ÖøßCE£¬¼¤·¢Êý¾Ý·¢ËÍ } void NRF_TxPacket_AP(uint8_t * tx_buf, uint8_t len) { SPI_CE_L(); //StandBy Iģʽ NRF_Write_Buf(0xa8, tx_buf, len); // ×°ÔØÊý¾Ý SPI_CE_H(); //ÖøßCE } u8 Nrf24l01_Check(void) { u8 buf1[5]; u8 i; /*дÈë5¸ö×ֽڵĵØÖ·. */ NRF_Write_Buf(NRF_WRITE_REG+TX_ADDR,TX_ADDRESS,5); /*¶Á³öдÈëµÄµØÖ· */ NRF_Read_Buf(TX_ADDR,buf1,5); /*±È½Ï*/ for(i=0;i<5;i++) { if(buf1[i]!=TX_ADDRESS[i]) break; } if(i==5) return SUCCESS ; //MCUÓëNRF³É¹¦Á¬½Ó else return ERROR ; //MCUÓëNRF²»Õý³£Á¬½Ó } void Nrf24l01_Init(u8 model) { SPI_CE_L(); NRF_Write_Buf(NRF_WRITE_REG+RX_ADDR_P0,RX_ADDRESS,RX_ADR_WIDTH); //дRX½ÚµãµØÖ· NRF_Write_Buf(NRF_WRITE_REG+TX_ADDR,TX_ADDRESS,TX_ADR_WIDTH); //дTX½ÚµãµØÖ· NRF_Write_Reg(NRF_WRITE_REG+EN_AA,0x00); //ʹÄÜͨµÀ0µÄ×Ô¶¯Ó¦´ð NRF_Write_Reg(NRF_WRITE_REG+EN_RXADDR,0x01); //ʹÄÜͨµÀ0µÄ½ÓÊÕµØÖ· NRF_Write_Reg(NRF_WRITE_REG+SETUP_RETR,0x00); //ÉèÖÃ×Ô¶¯ÖØ·¢¼ä¸ôʱ¼ä:500us;×î´ó×Ô¶¯ÖØ·¢´ÎÊý:10´Î NRF_Write_Reg(NRF_WRITE_REG+RF_CH,40); //ÉèÖÃRFͨµÀΪCHANAL NRF_Write_Reg(NRF_WRITE_REG+RF_SETUP,0x0f); //ÉèÖÃTX·¢Éä²ÎÊý,0dbÔöÒæ,2Mbps,µÍÔëÉùÔöÒ濪Æô if(model==1) //RX { NRF_Write_Reg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //Ñ¡ÔñͨµÀ0µÄÓÐЧÊý¾Ý¿í¶È NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0f); // IRQÊÕ·¢Íê³ÉÖжϿªÆô,16λCRC,Ö÷½ÓÊÕ } else if(model==2) //TX { NRF_Write_Reg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //Ñ¡ÔñͨµÀ0µÄÓÐЧÊý¾Ý¿í¶È NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0e); // IRQÊÕ·¢Íê³ÉÖжϿªÆô,16λCRC,Ö÷·¢ËÍ } else if(model==3) //RX2 { NRF_Write_Reg(FLUSH_TX,0xff); NRF_Write_Reg(FLUSH_RX,0xff); NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0f); // IRQÊÕ·¢Íê³ÉÖжϿªÆô,16λCRC,Ö÷½ÓÊÕ Spi_RW(0x50); Spi_RW(0x73); NRF_Write_Reg(NRF_WRITE_REG+0x1c,0x01); NRF_Write_Reg(NRF_WRITE_REG+0x1d,0x06); } else //TX2 { NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0e); // IRQÊÕ·¢Íê³ÉÖжϿªÆô,16λCRC,Ö÷·¢ËÍ NRF_Write_Reg(FLUSH_TX,0xff); NRF_Write_Reg(FLUSH_RX,0xff); Spi_RW(0x50); Spi_RW(0x73); NRF_Write_Reg(NRF_WRITE_REG+0x1c,0x01); NRF_Write_Reg(NRF_WRITE_REG+0x1d,0x06); } SPI_CE_H(); } u8 NRF24L01_RxPacket(u8 *rxbuf) { u8 state,flag; state=NRF_Read_Reg(NRF_READ_REG+NRFRegSTATUS); NRF_Write_Reg(NRF_WRITE_REG+NRFRegSTATUS,state); if(NRFRegSTATUS&RX_DR) // ÅжÏÊÇ·ñ½ÓÊÕµ½Êý¾Ý { NRF_Read_Buf(RD_RX_PLOAD ,rxbuf,RX_PLOAD_WIDTH);// ´ÓRXFIFO¶ÁÈ¡Êý¾Ý ½ÓÊÕ4λ¼´¿É£¬ºóһλλ½áÊøλ NRF_Write_Reg(FLUSH_RX,0xff);//ÓÃÓÚÇå¿ÕFIFO £¡£¡¹Ø¼ü£¡£¡²»È»»á³öÏÖÒâÏë²»µ½µÄºó¹û£¡£¡£¡´ó¼Ò¼Çס£¡ flag=1; return flag; } } |
|
|
|
额,代码还长,看起来真的是有心无力啊!楼主保重~
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
238 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
734 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1128 浏览 1 评论
LL库F030进行3个串口收发,2个串口为232,一个为485,长时间后,会出现串口1停止运行,另外两个正常,只有重启复原
1600 浏览 1 评论
538 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-9 15:01 , Processed in 0.692214 second(s), Total 76, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号