1 nRF24L01оƬµÄ½éÉÜ
nRF24L01Êǵ¥Æ¬ÉäƵÊÕ·¢Ð¾Æ¬£¬¹¤×÷ÓÚ2.4¡«2.5 GHz ISMƵ¶Î¡£¹¤×÷µçѹΪ1.9¡«3.6 V£¬Óжà´ï125¸öƵµÀ¿É¹©Ñ¡Ôñ¡£¿Éͨ¹ýSPIдÈëÊý¾Ý£¬×î¸ß¿É´ï10 Mb£¯s£¬Êý¾Ý´«ÊäÂÊ×î¿ì¿É´ï2 Mb£¯s£¬²¢ÇÒÓÐ×Ô¶¯Ó¦´ðºÍ×Ô¶¯ÔÙ·¢É书ÄÜ¡£ºÍÉÏÒ»´únRF2401Ïà±È£¬nRF2401Êý¾Ý´«ÊäÂʸü¿ì£¬Êý¾ÝдÈëËٶȸü¸ß£¬ÄÚǶµÄ¹¦ÄܸüÍ걸¡£
оƬÄÚÖÃƵÂʺϳÉÆ÷¡¢¹¦ÂÊ·Å´óÆ÷¡¢¾§ÌåÕñµ´Æ÷¡¢µ÷ÖÆÆ÷µÈ¹¦ÄÜÄ£¿é£¬²¢ÈÚ½øÁËÔöǿʽShockBurst¼¼Êõ£¬ÆäÖÐÊä³ö¹¦ÂʺÍͨÐÅƵµÀ¿Éͨ¹ý³ÌÐò½øÐÐÅäÖá£Ð¾Æ¬Äܺķdz£µÍ£¬ÒÔ-6 dBmµÄ¹¦ÂÊ·¢Éäʱ£¬¹¤×÷µçÁ÷Ö»ÓÐ9 mA£¬½ÓÊÕʱ¹¤×÷µçÁ÷Ö»ÓÐ12.3 mA£¬¶àÖֵ͹¦Âʹ¤×÷ģʽ(µôµçģʽºÍ¿ÕÏÐģʽ)ʹ½ÚÄÜÉè¼Æ¸ü·½±ã¡£
1.1 nRF24L01Òý½Å½éÉÜ
оƬÒý½ÅÅÅÁмûͼ1¡£
¸÷Òý½Å¾ßÌ幦ÄÜÈçÏ£ºCEΪ·¢ÉäºÍ½ÓÊÕµÄʹÄܶˣ»CSNΪSPIµÄʹÄܶˣ»SCKΪSPIʱÖÓÊäÈ룻MOSIΪSPIÊý¾ÝÖ÷Êä´ÓÈ˶ˣ»MISOΪSPIÊý¾ÝÖ÷ÈË´ÓÊä¶Ë£»IRQΪÖжÏÊä³ö£»VDDΪµçÔ´¶Ë£¬½Ó3 VÖ±Á÷µçÔ´£»VSSΪ²Î¿¼½ÓµØ¶Ë£»XC1£¬XC2Ϊ¾§Õñ¶Ë£»VDD_PA¸ø¹¦ÂÊ·Å´óÆ÷¹©µç1.8 V£»ANT1£¬ANT2ΪÌìÏ߽ӿڶˣ»IREFΪ²Î¿¼µçÁ÷¶Ë¡£
1.2 nRF24L01µÄÖ¸Áî½á¹¹
nRF24L01ËùÓеÄÅäÖÃ×Ö¶¼ÓÉÅäÖüĴæÆ÷À´¶¨Ò壬ÕâЩÅäÖüĴæÆ÷¿Éͨ¹ýSPI¿Ú·ÃÎÊ¡£
1.2.1 SPI½Ó¿ÚÉèÖÃ
SPI½Ó¿ÚÓÉSCK£¬MOSI£¬MISO¼°CSN×é³É¡£
(1)ÔÚÅäÖÃģʽϵ¥Æ¬»úͨ¹ýSPI½Ó¿ÚÅäÖÃnRF24L01µÄ¹¤×÷²ÎÊý¡£
(2)ÔÚ·¢Éä»ò½ÓÊÕģʽϵ¥Æ¬»úSPI½Ó¿Ú·¢ËÍ»ò½ÓÊÕÊý¾Ý¡£
ºÍSPI½Ó¿ÚµÄÖ¸Áî¹²ÓÐ8¸ö£¬Ê¹ÓÃÿ¸öÖ¸Áîʱ±ØÐëʹCSN±äµÍ£¬ÓÃÍêºó½«Æä±ä¸ß¡£µ¥Æ¬»úµÄ¿ØÖÆÖ¸Áî´ÓnRF24L01µÄMOSIÒý½ÅÊäÈ룬¶ønRF24L01µÄ״̬ÐÅÏ¢ºÍÊý¾ÝÐÅÏ¢ÊÇ´ÓÆäMISOÒý½ÅÊä³ö²¢Ë͸øµ¥Æ¬»úµÄ¡£ÀûÓÃSPI´«Êýʱ£¬ËûÊÇÏÈ´«µÍλ×Ö½Ú£¬ÔÙ´«¸ßλ×Ö½Ú£¬²¢ÇÒÔÚ´«Ã¿¸ö×Ö½ÚʱÊÇ´Ó¸ßλ×Ö½Ú´«ÆðµÄ¡£Ö¸Áî·Ö±ðÊÇ£»¶Á¼Ä´æÆ÷Ö¸Á¸ñʽÊÇ000A AAAA£»Ð´¼Ä´æÆ÷Ö¸Á¸ñʽÊÇ001AAAAA(A AAAA´ú±í¼Ä´æÆ÷ÔÚÄÚ´æÖеĵØÖ·£»¶ÁPayloadÖ¸ÁдPayloadÖ¸ÁÇå·¢Éä¶ÑÕ»Ö¸ÁÇå½ÓÊÕ¶ÑÕ»Ö¸Á·¢ÉäÊý¾ÝÔÙÀûÓ㻿ղÙ×÷¡£
1.2.2 ÖжÏ
¡¡
¡¡¡¡µ±nRF24L01µÄÖжÏÔ´(TX_DS£¬RX_DR£¬MAX_RT)±»Öøßʱ(TX_DSΪ·¢Ëͳɹ¦±ê־룬RX_DRΪ½ÓÊÕÊý¾Ý³É¹¦±ê־룬MAX_RTΪ×Ô¶¯ÖØ·¢³¬ÉÏÏÞ±ê־λ)£¬¾Í»áʹIRQÒý½ÅÖõ͡£¿ÉÒÔÏò״̬¼Ä´æÆ÷д1À´ÇåÕâЩÖжϱê־λ¡£Í¨¹ýÉèÖÃCONFIG¼Ä´æÆ÷µÄijЩλÀ´ÆÁ±ÎµôÕâЩÖжÏÔ´£¬Ä¬ÈÏÇé¿öÏ£¬ÕâÈý¸öÖжÏÔ´¶¼ÊÇÔÊÐíµÄ¡£
1.2.3 ÄÚ´æÇø
ÏÂÃæ½éÉÜnRF24L01µÄÄÚ´æÇø£¬Ò»¹²24¸ö¼Ä´æÆ÷£¬ÒÔÏÂÑ¡È¡¼¸¸öÖØÒªµÄ¼ÓÒÔ½éÉÜ¡£
0ºÅ¼Ä´æÆ÷£ºµÚ7λÊDZ£Áôλ£»µÚ6λµ½µÚ4λ·Ö±ðÊÇTX_DS£¬RX_DR£¬MAX_RTÆÁ±Î룬ÖøßÄÜÆÁ±ÎÏàÓ¦µÄÖжÏÔ´£»µÚ3λÊÇCRCʹÄÜλ£»µÚ2λÊÇÑ¡ÔñCRC³¤¶È£»µÚ1λÊÇPWR_UP룬¸ßµçƽΪʹоƬÉϵ磻µÚ0λÊÇ·¢Éä¡¢½ÓÊÕÑ¡Ôñ룬¸ßµçƽÊÇ·¢É䣬µÍµçƽÊǽÓÊÕ¡£
1ºÅ¼Ä´æÆ÷£ºµÚ7ºÍµÚ6λÊDZ£Áô룬µÚ5µ½µÚ0λÊÇʹÄÜͨµÀ5µ½Í¨µÀ0µÄ×Ô¶¯Ó¦´ð£¬¸ßµçƽÓÐЧ¡£
2ºÅ¼Ä´æÆ÷£ºµÚ7ºÍµÚ6λÊDZ£Áô룬µÚ5µ½µÚ0λÊÇʹÄܽÓÊÕͨµÀµØÖ·5µ½µØÖ·0£¬¸ßµçƽÓÐЧ¡£
4ºÅ¼Ä´æÆ÷£ºµÚ7λµ½µÚ4λÊÇÉèÖÃ×Ô¶¯ÖØ·¢µÄʱ¼ä£¬µÚ3λµ½µÚ0λÊÇÉèÖÃ×Ô¶¯ÖØ·¢µÄ´ÎÊý¡£
7ºÅ¼Ä´æÆ÷ÊÇ״̬¼Ä´æÆ÷£¬µÚ7λÊDZ£Áô룬µÚ6λÊÇRX_DRλ(1£º½ÓÊÕ¶ÑÕ»ÖÐÓÐÁËÊý¾Ý)£¬µÚ5λÊÇTX_DSλ(1£ºÊý¾Ý³É¹¦·¢Ë͵½½ÓÊÕ·½)£¬µÚ4λÊÇMAX_RTλ(1£º´ïµ½ÖØ·¢ÉäÉÏÏÞ£¬²úÉú³¬Ê±ÖжÏ)£¬µÚ3µ½µÚ1λÊDZêÖ¾ÄĸöͨµÀ½ÓÊÕÊý¾Ý£¬µÚ0λÊÇ·¢Éä¶Ñջ״̬λ¡£
1.3 nRF24L01µÄ¹¦ÄÜÃèÊö
nRF24L01¿ÉÒÔͨ¹ýÉèÖÃCEºÍ״̬¼Ä´æÆ÷À´Ñ¡ÔñËûµÄ¹¤×÷״̬£¬Èç±í1Ëùʾ¡£
ÅäÖÃΪ·¢ÉäģʽµÄnRF24L01½«»áÀûÓÃÔöǿʽShockBurst¼¼ÊõÀ´·¢ÉäÊý¾Ý°ü¡£·¢ËÍÉ豸ÔÚ·¢ÍêÊý¾Ýºó½«×Ô¶¯×ªÎª½ÓÊÕ״̬À´µÈ´ý½ÓÊÕ·½µÄÓ¦´ðÐźš£Èô·¢ËÍÉ豸δ½ÓÊÕµ½Ó¦´ðÐźţ¬Ëû½«×Ô¶¯ÖØ·¢Õâ°üÊý¾Ý(×Ô¶¯ÖØ·¢¿ªÆôµÄÇé¿öÏÂ)Ö±µ½½ÓÊÕÕâ°üÊý¾Ý»òÕßÖØ·¢´ÎÊý³¬¹ýÁËÔڼĴæÆ÷SETUP_RETR_ARCÉèÖõÄËùÔÊÐíµÄ×î´óÖØ·¢´ÎÊý¡£Èç¹ûÊǵڶþÖÖÇé¿ö£¬Ëû½«ÔÚSTATUS¼Ä´æÆ÷ÀïµÄMAX_RTλ·´Ó³³öÀ´£¬²¢ÇÒ¸ø³öÖжϡ£
µ±nRF24L01ÊÕµ½Ó¦´ðÐźÅʱ£¬Ëû½«ÈÏΪ¸Ã°üÊý¾Ý³É¹¦·¢Ë͵½½ÓÊÕ·½£¬²¢°ÑÕâ°üÊý¾Ý´Ó·¢Éä¶ÑÕ»ÖÐÇå³ý£¬Í¬Ê±IRQ±äµÍ£¬STATUS¼Ä´æÆ÷ÀïµÄÖжϱê־λTX_DSÖøߡ£
ÓÃÔöǿʽShockBurst¼¼ÊõÀ´·¢ÉäÊý¾Ý¿ÉÒÔÓÐÒÔϺô¦£º¼«´óµØ½µµÍÁ˵çÁ÷ËðºÄ£»ÏµÍ³¿ªÏúµÍ£»¼«´óµØ½µµÍÁËÊý¾ÝÔÚ¿ÕÆøÖеÄÅöײÂÊ¡£
2 ϵͳÉè¼Æ
2.1 Ó²¼þÉè¼Æ
±¾ÏµÍ³²ÉÓõĵ¥Æ¬»úÊÇPIC16F877£¬½«µ¥Æ¬»úµÄPORTCµÄ0¡«5ÅäÖóÉͨÓÃI£¯OÒý½Å£¬·Ö±ðÓënRF24L01µÄIRQ£¬CE£¬CSN£¬SCK£¬MOSI£¬MISOÁ¬½Ó£¬¿ØÖÆnRF24L01µÄ¹¤×÷·½Ê½£¬²ÉÓõ¥Æ¬»ú±ê×¼µÄSPI½Ó¿Ú¡£ÏµÍ³Éϵçʱ£¬PIC16F877Ê×ÏȶÔnRF24L01½øÐÐдÅäÖüĴæÆ÷²Ù×÷£¬È»ºóʹnRF24L01½øÈë·¢Éä״̬£¬½«Òª·¢Ë͵ÄÊý¾ÝдÈënRF24L01£¬¼¤»îÎÞÏß·¢É䡣Ȼºó¼ì²ânRF24L01µÄIRQÒý½Å£¬ÓÉÓڹرÕÁË×Ô¶¯ÖØ·¢É书ÄÜ£¬Òò´ËÈç¹ûÒý½Åµçƽ±äµÍ£¬¼´ËµÃ÷²úÉú·¢Ëͳɹ¦Öжϣ¬Êý¾Ý·¢Ëͳɹ¦£¬È»ºó´Ó½ÓÊն˶Á³öÊý¾Ý¼´¿É¡£
2.2Èí¼þÉè¼Æ
³ÌÐòÁ÷³ÌͼÈçͼ3Ëùʾ¡£³ÌÐò±à³ÌµÄ»ù±¾Ë¼Â·ÊÇ£¬ÏµÍ³ÉϵçÊ×ÏÈÅäÖÃnRF24L01µÄ¼Ä´æÆ÷£¬±¾ÏµÍ³Ö»¶ÔÆäÖм¸¸ö¼Ä´æÆ÷½øÐÐÁËÖØÐÂÅäÖ㬹رÕ×Ô¶¯ÖØ·¢É书ÄÜÊÇÏë¶Ô·¢ËÍʧ°Ü´ÎÊý½øÐÐͳ¼Æ£¬ÆäËûµÄ¾ù²ÉÓÃĬÈÏÖµ£¬È磺ͨÐÅËÙÂÊ2 Mb£¯s£¬Êä³ö¹¦ÂÊ0 dBmµÈ¡£
nRF24L01дÅäÖÃ×Ó³ÌÐòÈçÏ£º
3 ½á Óï
±¾ÎĽéÉÜÁËÀûÓÃPIC16F877ºÍnRF24L01оƬÉè¼ÆµÄÎÞÏßÊý¾Ý´«Êäϵͳ£¬³É±¾µÍ£¬Ìå»ýС£¬´«ÊäËÙÂʸߣ¬¾ßÓÐÁ¼ºÃµÄͨÓÃÐԺͿɿ¿ÐÔ£¬¿É¹©¼à²âºÍ¹¤Òµ¿ØÖÆϵͳµç·Éè¼Æ²Î¿¼Ê¹Óá£