CCS snippets

Discussion about wireless devices

CCS snippets

Postby bdeb » Wed Feb 17, 2010 9:29 am


Here are some (hopefully) handy code snippets.
Written for the CCS compiler, but pretty easy to change.



Code: Select all
//Called when interrupt occurs or after polling for IRQ-pin==high

void nrf24IRQ(void)
   unsigned char config;
   unsigned char res;

   res = nrf24RdReg(RF_CONFIG, &config, 1);

   F_IntRxOK = bit_test(res,6);
   F_IntTxOK = bit_test(res,5);
   F_IntTxErr = bit_test(res,4);

   if(F_IntRxOK && F_IntTxOK ) { F_IntAckPlOK=TRUE; } // Ack payload recieved
   else if(F_IntRxOK) { output_bit(P_NRF24CE,0); } //Disable receiver!
   else if(F_IntTxErr) { nrf24FlushTx(); }


Code: Select all
//Don´t miss any data in Rx FIFO!

   #define FIFOMAX 3   //Max messages in RxFIFO
   int8 data[5];
   int8 stat;
   int8 fifo;
   int8 pipe;
   int8 i;
      stat = nrf24GetRxData(&data, 1);   //Get received data
      pipe= (stat & 0x0E) >> 1;      //Check what pipe it was received on

      printf("P%d=%X\x01",pipe, data[0]);

      nrf24RdReg(RF_FIFO_STATUS, &fifo, 1);
      if(bit_test(fifo,0)) { break; } //RX_EMPTY set, don´t read another

Posts: 8
Joined: Tue Feb 16, 2010 10:40 pm

Return to Wireless

Who is online

Users browsing this forum: No registered users and 2 guests