{"id":497,"date":"2013-09-22T18:14:26","date_gmt":"2013-09-22T16:14:26","guid":{"rendered":"http:\/\/labalec.fr\/erwan\/?p=497"},"modified":"2023-11-26T14:08:54","modified_gmt":"2023-11-26T13:08:54","slug":"arduino-and-texas-cc1101","status":"publish","type":"post","link":"https:\/\/labalec.fr\/erwan\/?p=497","title":{"rendered":"Arduino : use a Texas CC1101"},"content":{"rendered":"<p>In \u00a0a <a href=\"https:\/\/labalec.fr\/erwan\/?p=261\" target=\"_blank\" rel=\"noopener\">previous article<\/a>, we have seen how to use RF433 chips with Arduino.<\/p>\n<p>Pros for these chips are they are cheap and easy to use, cons is that they provide little or no tuning.<\/p>\n<p>Hence, lets play a bit now with 2 texas <a href=\"http:\/\/dx.com\/p\/cc1101-wireless-module-w-external-antenna-blue-160898\" target=\"_blank\" rel=\"noopener\">cc1101<\/a>\u00a0: with this component, we can play with the frequency (from 315 to 915), the modulation (ask, fsk, etc) and tons of other parameters.<\/p>\n<p>You can use <a href=\"http:\/\/www.ti.com\/tool\/smartrftm-studio\" target=\"_blank\" rel=\"noopener\">smartRF <\/a>(optional) to dive into parameters.<\/p>\n<p>First lets start with the pins of the cc1101.<\/p>\n<p><a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/09\/spi.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-498\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/09\/spi-266x300.png\" alt=\"spi\" width=\"266\" height=\"300\" srcset=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/09\/spi-266x300.png 266w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/09\/spi.png 605w\" sizes=\"auto, (max-width: 266px) 100vw, 266px\" \/><\/a><\/p>\n<p>Here how it will connect to the arduino uno board (see <a href=\"http:\/\/arduino.cc\/en\/Reference\/SPI\" target=\"_blank\" rel=\"noopener\">here<\/a> for other boards) :<\/p>\n<p><a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/09\/cc1101_2_bb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-499\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/09\/cc1101_2_bb-300x251.png\" alt=\"cc1101_2_bb\" width=\"300\" height=\"251\" srcset=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/09\/cc1101_2_bb-300x251.png 300w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/09\/cc1101_2_bb-1024x859.png 1024w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/09\/cc1101_2_bb.png 1755w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>To use the CC1101, you will need the panstamp library <a href=\"https:\/\/code.google.com\/p\/panstamp\/downloads\/detail?name=panstamp_arduino_1.0.zip&amp;can=2&amp;q=\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p>Note that it will also work with the elechouse library <a href=\"http:\/\/www.elechouse.com\/elechouse\/index.php?main_page=product_info&amp;products_id=802\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p>The initial <a href=\"http:\/\/forum.arduino.cc\/index.php?topic=169829.0\" target=\"_blank\" rel=\"noopener\">thread<\/a> on the Arduino forum.<\/p>\n<p>Now lets have a look at the sketches.<\/p>\n<p><strong>Sending <\/strong>&#8230;<\/p>\n<pre>#include \"EEPROM.h\"\n#include \"cc1101.h\"\n\nCC1101 cc1101;\n\n\/\/ The LED is wired to the Arduino Output 4 (physical panStamp pin 19)\n#define LEDOUTPUT 7\n\n\/\/ counter to get increment in each loop\nbyte counter;\nbyte b;\n\/\/byte syncWord = 199;\nbyte syncWord[2] = {199, 0};\n\nvoid blinker(){\ndigitalWrite(LEDOUTPUT, HIGH);\ndelay(100);\ndigitalWrite(LEDOUTPUT, LOW);\ndelay(100);\n}\n\nvoid setup()\n{\nSerial.begin(38400);\nSerial.println(\"start\");\n\n\/\/ setup the blinker output\npinMode(LEDOUTPUT, OUTPUT);\ndigitalWrite(LEDOUTPUT, LOW);\n\n\/\/ blink once to signal the setup\nblinker();\n\n\/\/ reset the counter\ncounter=0;\nSerial.println(\"initializing...\");\n\/\/ initialize the RF Chip\ncc1101.init();\n\n\/\/cc1101.setSyncWord(&amp;syncWord, false);\ncc1101.setSyncWord(syncWord, false);\ncc1101.setCarrierFreq(CFREQ_433);\ncc1101.disableAddressCheck();\n\/\/cc1101.setTxPowerAmp(PA_LowPower);\n\ndelay(1000);\n\nSerial.print(\"CC1101_PARTNUM \"); \/\/cc1101=0\nSerial.println(cc1101.readReg(CC1101_PARTNUM, CC1101_STATUS_REGISTER));\nSerial.print(\"CC1101_VERSION \"); \/\/cc1101=4\nSerial.println(cc1101.readReg(CC1101_VERSION, CC1101_STATUS_REGISTER));\nSerial.print(\"CC1101_MARCSTATE \");\nSerial.println(cc1101.readReg(CC1101_MARCSTATE, CC1101_STATUS_REGISTER) &amp; 0x1f);\n\nSerial.println(\"device initialized\");\n\/\/Serial.println(\"done\");\n}\n\nvoid send_data() {\nCCPACKET data;\ndata.length=10;\nbyte blinkCount=counter++;\ndata.data[0]=5;\ndata.data[1]=blinkCount;data.data[2]=0;\ndata.data[3]=1;data.data[4]=0;\n\/\/cc1101.flushTxFifo ();\nSerial.print(\"CC1101_MARCSTATE \");\nSerial.println(cc1101.readReg(CC1101_MARCSTATE, CC1101_STATUS_REGISTER) &amp; 0x1f);\nif(cc1101.sendData(data)){\nSerial.print(blinkCount,HEX);\nSerial.println(\" sent ok :)\");\nblinker();\n}else{\nSerial.println(\"sent failed :(\");\nblinker();\nblinker();\n}\n}\n\nvoid loop()\n{\nsend_data();\ndelay(4000);\n}\n<\/pre>\n<p><strong>Receiving <\/strong>&#8230;<\/p>\n<pre>#include \"EEPROM.h\"\n#include \"cc1101.h\"\n\n\/\/ The LED is wired to the Arduino Output 4 (physical panStamp pin 19)\n#define LEDOUTPUT 4\n\n\/\/ The connection to the hardware chip CC1101 the RF Chip\nCC1101 cc1101;\n\nbyte b;\nbyte i;\nbyte syncWord = 199;\nlong counter=0;\nbyte chan=0;\n\n\/\/ a flag that a wireless packet has been received\nboolean packetAvailable = false;\n\nvoid blinker(){\ndigitalWrite(LEDOUTPUT, HIGH);\ndelay(100);\ndigitalWrite(LEDOUTPUT, LOW);\ndelay(100);\n}\n\n\/* Handle interrupt from CC1101 (INT0) gdo0 on pin2 *\/\nvoid cc1101signalsInterrupt(void){\n\/\/ set the flag that a package is available\npacketAvailable = true;\n}\n\nvoid setup()\n{\nSerial.begin(38400);\nSerial.println(\"start\");\n\n\/\/ setup the blinker output\npinMode(LEDOUTPUT, OUTPUT);\ndigitalWrite(LEDOUTPUT, LOW);\n\n\/\/ blink once to signal the setup\nblinker();\n\/\/ initialize the RF Chip\ncc1101.init();\n\ncc1101.setSyncWord(&amp;syncWord, false);\ncc1101.setCarrierFreq(CFREQ_433);\ncc1101.disableAddressCheck(); \/\/if not specified, will only display \"packet received\"\n\/\/cc1101.setTxPowerAmp(PA_LowPower);\n\nSerial.print(\"CC1101_PARTNUM \"); \/\/cc1101=0\nSerial.println(cc1101.readReg(CC1101_PARTNUM, CC1101_STATUS_REGISTER));\nSerial.print(\"CC1101_VERSION \"); \/\/cc1101=4\nSerial.println(cc1101.readReg(CC1101_VERSION, CC1101_STATUS_REGISTER));\nSerial.print(\"CC1101_MARCSTATE \");\nSerial.println(cc1101.readReg(CC1101_MARCSTATE, CC1101_STATUS_REGISTER) &amp; 0x1f);\n\nattachInterrupt(0, cc1101signalsInterrupt, FALLING);\n\nSerial.println(\"device initialized\");\n}\n\nvoid ReadLQI()\n{\nbyte lqi=0;\nbyte value=0;\nlqi=(cc1101.readReg(CC1101_LQI, CC1101_STATUS_REGISTER));\nvalue = 0x3F - (lqi &amp; 0x3F);\nSerial.print(\"CC1101_LQI \");\nSerial.println(value);\n}\n\nvoid ReadRSSI()\n{\nbyte rssi=0;\nbyte value=0;\n\nrssi=(cc1101.readReg(CC1101_RSSI, CC1101_STATUS_REGISTER));\n\nif (rssi &gt;= 128)\n{\nvalue = 255 - rssi;\nvalue \/= 2;\nvalue += 74;\n}\nelse\n{\nvalue = rssi\/2;\nvalue += 74;\n}\nSerial.print(\"CC1101_RSSI \");\nSerial.println(value);\n}\n\nvoid loop()\n{\nif(packetAvailable){\nSerial.println(\"packet received\");\n\/\/ Disable wireless reception interrupt\ndetachInterrupt(0);\n\nReadRSSI();\nReadLQI();\n\/\/ clear the flag\npacketAvailable = false;\n\nCCPACKET packet;\n\nif(cc1101.receiveData(&amp;packet) &gt; 0){\nif(!packet.crc_ok) {\nSerial.println(\"crc not ok\");\n}\n\nif(packet.length &gt; 0){\nSerial.print(\"packet: len \");\nSerial.print(packet.length);\nSerial.print(\" data: \");\nfor(int j=0; j&lt;packet.length; j++){\nserial.print(packet.data[j],hex);\nserial.print(\" \");\n}\nserial.println(\".\");\n\n\u00a0}\n}\n \/\/ Enable wireless reception interrupt\u00a0attachInterrupt(0, cc1101signalsInterrupt, FALLING);\n}\n}<\/pre>\n<pre>Voila :)\nYou know should not a bit better on the cc1101 pins, on how to connect it to the arduino and you have basic code to developp your projects.<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In \u00a0a previous article, we have seen how to use RF433 chips with Arduino. Pros for these chips are they are cheap and easy to use, cons is that they provide little or no tuning. Hence, lets play a bit now with 2 texas cc1101\u00a0: with this component, we can play with the frequency (from <a href='https:\/\/labalec.fr\/erwan\/?p=497' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-497","post","type-post","status-publish","format-standard","hentry","category-arduino","category-18-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/497","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=497"}],"version-history":[{"count":19,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/497\/revisions"}],"predecessor-version":[{"id":2497,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/497\/revisions\/2497"}],"wp:attachment":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}