CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

si4432 module

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
datvo06



Joined: 22 Feb 2014
Posts: 6

View user's profile Send private message

si4432 module
PostPosted: Sat Feb 22, 2014 10:27 pm     Reply with quote

Hi everyone.
I've been trying to get si4432 module to work for several weeks but no luck. I can't figure out what's the problem, it seems that tx is working but I am unable to receive packets.

Can anyone provide a simple working code for si4432 & ccs please ?

Thanks for you guys help!
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Sun Feb 23, 2014 1:59 am     Reply with quote

First, if this is a new product, look at the 4460 instead.
The 4430, is obsolete, and is not guaranteed to be available for much longer. Doing a lot of work on an old product, can be rather a wasted exercise....
There are also a lot of errata for this unit. Have you looked at these?.
Are you running direct mode, or FIFO mode?.

Best Wishes
datvo06



Joined: 22 Feb 2014
Posts: 6

View user's profile Send private message

PostPosted: Sun Feb 23, 2014 2:43 am     Reply with quote

Hi Ttelmah,
I tried that, using the excel, translating example code from hoperf and the example code for 8051 to ccs, I'm using software spi from hoperf code and FIFO mode.
also, I got wrong nIRQ signal in Rx and I cant get pass

Code:
//SW reset
SpiWriteRegister(0x07, 0x80); //write 0x80 to the Operating & Function Control1 register //wait for POR interrupt from the radio (while the nIRQ pin is high)
while ( NIRQ == 1);
//read interrupt status registers to clear the interrupt flags and release NIRQ pin
ItStatus1 = SpiReadRegister(0x03); //read the Interrupt Status1 register
ItStatus2 = SpiReadRegister(0x04); //read the Interrupt Status2 register
//wait for chip ready interrupt from the radio (while the nIRQ pin is high)
while ( NIRQ == 1); // I cant get past this line until I remove it.
Thanks for your reply Smile
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Feb 23, 2014 6:24 am     Reply with quote

When posting please tell us what PIC you're using,a 'link' to the 'module' that doesn't work right,whether the device is a handsoldered chip or a PCB unit.Also a small,compilable program we can download to test.
Problems are in two catagories, hardware and software.Have you run any basic PIC test programs(1Hz LED, Hello World) to confirm it's 'alive and well'.If the 'module' or 'device' needs a driver, post that. Can you communicate with the device(setting and read back a register ?).
NIRQ.Hmm..have you enabled the appropriate interrupt and cut a good ISR for the PIC(which we don't know...)? Did you test the ISR manually(with a switch, not the device)?
I did lookup the device,saw that it's a 3 volt unit.Obvious hardware issue would be 5V PIC- 3V device.Seems there's a LOT of Ardunio code you could look at after all C is C, more or less....
bottom line, the more info you supply, thre better we can 'armchair diagnose' !

hth
jay
datvo06



Joined: 22 Feb 2014
Posts: 6

View user's profile Send private message

PostPosted: Sun Feb 23, 2014 7:24 am     Reply with quote

sorry, this is the first time I've ever been posting. Anyway, I'm using pic18f2550 smd and the mcu,connection,spi are fine. I'm testing module on two ordered PCB.
here're the codes:
for RX:
Code:

#include <main.h>
#include <string.h>
#use FIXED_IO( A_outputs=PIN_A0,PIN_A1,PIN_A2,PIN_A3,PIN_A4,PIN_A5 )
#use FIXED_IO( B_outputs=PIN_B4,PIN_B3,PIN_B2,PIN_B0 )

#define SDN    PIN_B0
#define nIRQ   PIN_B1
#define nSEL   PIN_B2
#define SCK    PIN_B3
#define SDI    PIN_B4
#define SDO    PIN_B5
//
#define STATION_1 PIN_A3
#define STATION_2 PIN_A4
#define STATION_3 PIN_A5
#define RUN_USB   PIN_A2
#define  TXON     PIN_A0
#define  RXON     PIN_A1

//============================
typedef unsigned char uchar;
typedef unsigned int    uint;
 
#define RF22_PWRSTATE_READY    01
#define RF22_PWRSTATE_RX        05
#define RF22_Rx_packet_received_interrupt   0x02
#define RF22_PWRSTATE_POWERDOWN   00

uchar ItStatus1,ItStatus2;
uchar RF_RXBUF[35];
 
void to_rx_mode(void);   
void to_ready_mode(void);
uchar spi_read_rf(uchar address);
void send_read_address(uchar i);
uchar read_8bit_data(void);
 
void spi_write_rf(uchar address, uchar data);
void send_8bit_data(uchar i);
void Write8bitcommand(uchar command);
 
void RF22_init_parameter(void);
void delay_50ms(void);
void delay_5ms(void);
void delay_1ms(void);
void port_init(void);   
void power_on_delay(void);
void Write0( void );
void Write1( void );
void to_sleep_mode(void);

unsigned char* check = "BUTTON1";

void main()
{
   //setup_timer_2(T2_DIV_BY_1,166,2);
   //setup_ccp1(CCP_PWM);
   output_bit(STATION_1,0);
   output_bit(RUN_USB,0);
   output_bit(RXON,0);
   output_bit(TXON,0);
   output_float(PIN_B5);
   output_high(PIN_A2);
   output_float(nIRQ);
   RF22_init_parameter();
   while(true)
   {
   to_rx_mode();
   }
}

void RF22_init_parameter()
{
   output_low(SDN);
   delay_ms(20);
   
   ItStatus1 = spi_read_rf(0x03);
   ItStatus2 = spi_read_rf(0x04);
   spi_write_rf(0x07,0x80);
   
   while(input(nIRQ));
   
   ItStatus1 = spi_read_rf(0x03);
   ItStatus2 = spi_read_rf(0x04);
   /*spi_write_rf(0x75,0x53);
   spi_write_rf(0x76,0x7D);
   spi_write_rf(0x77,0x00);*/
   spi_write_rf(0x75,0x75);
 spi_write_rf(0x76,0xBB);
 spi_write_rf(0x77,0x80);
   spi_write_rf(0x1C,0x05);
   spi_write_rf(0x20,0xA1);
   spi_write_rf(0x21,0x20);
   spi_write_rf(0x22,0x4E);
   spi_write_rf(0x23,0xA5);
   spi_write_rf(0x24,0x00);
   spi_write_rf(0x25,0x13);
   spi_write_rf(0x1D,0x40);
   spi_write_rf(0x72,0x1F);
   spi_write_rf(0x2A,0x20);
   spi_write_rf(0x33,0x02);
   spi_write_rf(0x32,0x00);
   spi_write_rf(0x36,0x2D);
   spi_write_rf(0x37,0xD4);
   spi_write_rf(0x30,0x85);
   spi_write_rf(0x71,0x63);
   spi_write_rf(0x35,0x28);
   spi_write_rf(0x34,0x0A);
   spi_write_rf(0x0C,0x12);
   spi_write_rf(0x0D,0x15);
   spi_write_rf(0x5A,0x7F);
   spi_write_rf(0x58,0x80);
   spi_write_rf(0x59,0x40);
   spi_write_rf(0x6A,0x0B);
   spi_write_rf(0x68,0x04);
   spi_write_rf(0x1F,0x03);
   spi_write_rf(0x09,0xD7);
   uchar a= spi_read_rf(0x01);
   if(a==0x07) output_high(TXON);
   spi_write_rf(0x07,0x05);
   spi_write_rf(0x05,0x03);
   spi_write_rf(0x06,0x00);
   ItStatus1 = spi_read_rf(0x03);
   ItStatus2 = spi_read_rf(0x04);
}

void to_rx_mode()
{
   if(!input(nIRQ))
   {
      ItStatus1 = spi_read_rf(0x03);
      /*if((ItStatus1 ==0)){
      output_low(RXON);
      delay_ms(1000);
      output_high(RXON);
      delay_ms(1000);
      output_low(RXON);
      }*/
      ItStatus2 = spi_read_rf(0x04);
      unsigned int8 length;
     
         length = spi_read_rf(0x4B);
         if(length==0)
         {
            output_low(RXON);
      delay_ms(1000);
      output_high(RXON);
      delay_ms(1000);
      output_low(RXON);
         }
      if( (ItStatus1&(0x01)) == 0x01)
      {
         spi_write_rf(0x07,0x01);
         spi_write_rf(0x08,0x02);
         spi_write_rf(0x08,0x00);
         output_high(RXON);
         delay_ms(10000);
         output_low(RXON);
      }
      else if((ItStatus1&(0x02)) == 0x02)
      {
         
         int8 i;
         for(i=0;i<8;i++)
         {
         output_bit(TXON,1);
         delay_ms(500);
         output_bit(TXON,0);
         delay_ms(500);
         }
         spi_write_rf(0x07,0x01);
         length = spi_read_rf(0x4B);
         if(length<11)
         {
            for(i=0;i<8;i++)
            {
               RF_RXBUF[i] = spi_read_rf(0x7F);
            }
            if(length ==8)
            {
               if(memcmp(&RF_RXBUF[0], check ,7) ==0)
               {
                  output_high(RXON);
                  output_high(TXON);
                  delay_ms(2000);
                  output_bit(RXON,0);
                  output_bit(TXON,0);
               }
            }
            if(RF_RXBUF[0]=='B')
            {
               
            //output_high(TXON);
               output_bit(RXON,0);
               delay_ms(1000);
            }
         }
         spi_write_rf(0x08,0x02);
         spi_write_rf(0x08,0x00);
         spi_write_rf(0x07,0x05);
      }
   }
}

//************************************************************
void Write0( void )
{
   // SCK=0;   
   // NOP();
   output_bit(SCK,0);
   delay_us(10);
     
   // SDI=0;
   // NOP();
   output_bit(SDI,0);
   delay_us(10);     
   // SCK=1;   
   // NOP();
      output_bit(SCK,1);
   delay_us(10);
}


//---------------------------------------------------------
void Write1( void )
{
 //SCK=0;   
 //   NOP();
   output_bit(SCK,0);
   delay_us(10);     
    //SDI=1;
    //NOP();
   output_bit(SDI,1);
   delay_us(10);
     
    //SCK=1;   
    //NOP();
   output_bit(SCK,1);
   delay_us(10);
}

//-----------------------------------------------------------------------
void Write8bitcommand(uchar command)    // keep sel to low
{
 uchar n=8;
 /*
    nSEL = 1;
    SCK=0;
    nSEL=0;
    */
    output_bit(nSEL,1);
    output_bit(SCK,0);
    output_bit(nSEL,0);
       while(n--)
    {
         if(command&0x80)
          Write1();
         else
          Write0();   
              command = command << 1;
    }
    //SCK=0;
    output_bit(SCK,0);


//-----------------------------------------------------------------------
uchar spi_read_rf(uchar address)
{
 uchar result;
 send_read_address(address);
 result = read_8bit_data();
  // nSEL = 1;
  output_bit(nSEL,1);
 return(result);


//-----------------------------------------------------------------------
void spi_write_rf(uchar address, uchar data)
{
 address |= 0x80;
 Write8bitcommand(address);
 send_8bit_data(data); 
  //nSEL = 1;
  output_bit(nSEL,1);
}
//-----------------------------------------------------------------------
void send_read_address(uchar i)
{
 i &= 0x7f;
 Write8bitcommand(i);

//-----------------------------------------------------------------------
void send_8bit_data(uchar i)
{
  uchar n = 8;
 //SCK=0;
 output_bit(SCK,0);
    while(n--)
    {
    if(i&0x80)
          Write1();
         else
          Write0();   
         i = i << 1;
    }
   // SCK=0;
   output_bit(SCK,0);

//-----------------------------------------------------------------------
uchar read_8bit_data(void)
{
  uchar Result, i;
 
 //SCK=0;
 output_bit(SCK,0);
 Result=0;
    for(i=0;i<8;i++)
    {                    //read fifo data byte
       Result=Result<<1;
      // SCK=1;
      // NOP();
      output_bit(SCK,1);
      delay_us(10);
       if(input(SDO))
       {
         Result|=1;
       }
      // SCK=0;
       //NOP();
       output_bit(SCK,0);
       delay_us(10);
     }
    return(Result);

//-----------------------------------------------------------------------
void to_sleep_mode(void)
{
    //TXEN = RXEN = 0;
  //LED_GREEN = 0;
  output_bit(TXON,0);
  output_bit(RXON,0);
  output_bit(RUN_USB,0);
  spi_write_rf(0x07, RF22_PWRSTATE_READY); 
   
    ItStatus1 = spi_read_rf(0x03);  //read the Interrupt Status1 register
  ItStatus2 = spi_read_rf(0x04);   
  spi_write_rf(0x07, RF22_PWRSTATE_POWERDOWN);
  while(1)
  {
   ;
  } 
}
//--------------------------------------------------------------


and TX:
Code:

#include <main.h>
#use FIXED_IO( A_outputs=PIN_A0,PIN_A1,PIN_A2 )
#use FIXED_IO( B_outputs=PIN_B4,PIN_B3,PIN_B2,PIN_B0 )
//
#define SDN    PIN_B0
#define nIRQ   PIN_B1
#define nSEL   PIN_B2
#define SCK    PIN_B3
#define SDI    PIN_B4
#define SDO    PIN_B5
//
#define  LED_RED  PIN_A2
#define  TXEN     PIN_A0
#define  RXEN     PIN_A1

//============================
typedef unsigned char uchar;
typedef unsigned int    uint;
 
#define RF22_PWRSTATE_READY    01
#define RF22_PWRSTATE_RX        05
#define RF22_Rx_packet_received_interrupt   0x02
#define RF22_PWRSTATE_POWERDOWN   00

uchar ItStatus1,ItStatus2;
uchar RF_RXBUF[35];
 
void to_tx_mode(void);   
void to_ready_mode(void);
uchar spi_read_rf(uchar address);
void send_read_address(uchar i);
uchar read_8bit_data(void);
 
void spi_write_rf(uchar address, uchar data);
void send_8bit_data(uchar i);
void Write8bitcommand(uchar command);
 
void RF22_init_parameter(void);
void delay_50ms(void);
void delay_5ms(void);
void delay_1ms(void);
void port_init(void);   
void power_on_delay(void);
void Write0( void );
void Write1( void );
void to_sleep_mode(void);

void main()
{
   RF22_init_parameter();
   //NOP();
   delay_us(10);
   while(TRUE)
   {
      to_tx_mode();
   }

}
//************************************************************
void Write0( void )
{
   // SCK=0;   
   // NOP();
   output_bit(SCK,0);
   delay_us(10);
     
   // SDI=0;
   // NOP();
   output_bit(SDI,0);
   delay_us(10);     
   // SCK=1;   
   // NOP();
      output_bit(SCK,1);
   delay_us(10);
}
//---------------------------------------------------------
void Write1( void )
{
 //SCK=0;   
 //   NOP();
   output_bit(SCK,0);
   delay_us(10);     
    //SDI=1;
    //NOP();
   output_bit(SDI,1);
   delay_us(10);
     
    //SCK=1;   
    //NOP();
   output_bit(SCK,1);
   delay_us(10);
}
//-----------------------------------------------------------------------
void Write8bitcommand(uchar command)    // keep sel to low
{
 uchar n=8;
 /*
    nSEL = 1;
    SCK=0;
    nSEL=0;
    */
    output_bit(nSEL,1);
    output_bit(SCK,0);
    output_bit(nSEL,0);
       while(n--)
    {
         if(command&0x80)
          Write1();
         else
          Write0();   
              command = command << 1;
    }
    //SCK=0;
    output_bit(SCK,0);

//-----------------------------------------------------------------------
uchar spi_read_rf(uchar address)
{
 uchar result;
 send_read_address(address);
 result = read_8bit_data();
  // nSEL = 1;
  output_bit(nSEL,1);
 return(result);

//-----------------------------------------------------------------------
void spi_write_rf(uchar address, uchar data)
{
 address |= 0x80;
 Write8bitcommand(address);
 send_8bit_data(data); 
  //nSEL = 1;
  output_bit(nSEL,1);
}

void RF22_init_parameter(void)
{
 output_low(SDN);
 delay_ms(20);
 ItStatus1 = spi_read_rf(0x03); // read status, clear interrupt   
 ItStatus2 = spi_read_rf(0x04);
 spi_write_rf(0x07,0x80);
 while(input(nIRQ));
 ItStatus1 = spi_read_rf(0x03); // read status, clear interrupt   
 ItStatus2 = spi_read_rf(0x04);
 //spi_write_rf(0x75,0x53);
 spi_write_rf(0x75,0x75);
 spi_write_rf(0x76,0xBB);
 spi_write_rf(0x77,0x80);
 //spi_write_rf(0x76,0x7D);
 //spi_write_rf(0x77,0x00);
 spi_write_rf(0x6E,0x4E);
 spi_write_rf(0x6F,0xA5);
 spi_write_rf(0x70,0x2C);
 spi_write_rf(0x72,0x48);
 spi_write_rf(0x34,0x0A);
 spi_write_rf(0x33,0x02);
 spi_write_rf(0x36,0x2D);
 spi_write_rf(0x37,0xD4);
 spi_write_rf(0x30,0x0D);
 spi_write_rf(0x71,0x63);
 spi_write_rf(0x0C,0x12);
 spi_write_rf(0x0D,0x15);
 spi_write_rf(0x5A,0x7F);
 spi_write_rf(0x59,0x40);
 spi_write_rf(0x09,0xD7);
 //spi_write_rf(0x5A,0x7F);
 //spi_write_rf(0x59,0x40);
 //spi_write_rf(0x09,0xD7);
}
//-----------------------------------------------------------------------
void send_read_address(uchar i)
{
 i &= 0x7f;
 Write8bitcommand(i);

//-----------------------------------------------------------------------
void send_8bit_data(uchar i)
{
  uchar n = 8;
 //SCK=0;
 output_bit(SCK,0);
    while(n--)
    {
    if(i&0x80)
          Write1();
         else
          Write0();   
         i = i << 1;
    }
   // SCK=0;
   output_bit(SCK,0);

//-----------------------------------------------------------------------
uchar read_8bit_data(void)
{
  uchar Result, i;
 
 //SCK=0;
 output_bit(SCK,0);
 Result=0;
    for(i=0;i<8;i++)
    {                    //read fifo data byte
       Result=Result<<1;
      // SCK=1;
      // NOP();
      output_bit(SCK,1);
      delay_us(10);
       if(input(SDO))
       {
         Result|=1;
       }
      // SCK=0;
       //NOP();
       output_bit(SCK,0);
       delay_us(10);
     }
    return(Result);

//-----------------------------------------------------------------------
void to_tx_mode(void)
{
   output_high(TXEN);
   spi_write_rf(0x3E,8);
   spi_write_rf(0x7F,0x42); //B
   spi_write_rf(0x7F,0x55);
   spi_write_rf(0x7F,0x54);
   spi_write_rf(0x7F,0x54);
   spi_write_rf(0x7F,0x4F);
   spi_write_rf(0x7F,0x4E);
   spi_write_rf(0x7F,0x31);
   spi_write_rf(0x7F,0x0D);
   
   spi_write_rf(0x05,0x04);
   spi_write_rf(0x06,0x00);
   ItStatus1 = spi_read_rf(0x03);
   ItStatus2 = spi_read_rf(0x04);
   spi_write_rf(0x05,0x04);
   
   spi_write_rf(0x07,0x09);
   ItStatus1 =spi_read_rf(0x03);
   ItStatus2 =spi_read_rf(0x04);
   
   while(input(nIRQ));
   ItStatus1 =spi_read_rf(0x03);
   ItStatus2 =spi_read_rf(0x04);
   delay_ms(500);
   output_low(TXEN);
   delay_ms(500);
}
//-----------------------------------------------------------------------
void to_ready_mode(void)
{
 ItStatus1 = spi_read_rf(0x03);   
 ItStatus2 = spi_read_rf(0x04);
 spi_write_rf(0x07, RF22_PWRSTATE_READY);
}
//-----------------------------------------------------------------------
void to_sleep_mode(void)
{
    //TXEN = RXEN = 0;
  //LED_GREEN = 0;
  output_bit(TXEN,0);
  output_bit(RXEN,0);
  output_bit(LED_RED,0);
  spi_write_rf(0x07, RF22_PWRSTATE_READY); 
   
    ItStatus1 = spi_read_rf(0x03);  //read the Interrupt Status1 register
  ItStatus2 = spi_read_rf(0x04);   
  spi_write_rf(0x07, RF22_PWRSTATE_POWERDOWN);
  while(1)
  {
   ;
  } 
}
//--------------------------------------------------------------

[/img]
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Feb 23, 2014 8:20 am     Reply with quote

hmm..could you post link to the RF PCB unit?
are you running PIC at 3 volts ?

there's no processor type include as the first line of your code....

does the PIC pass the 1Hz LED program ?

hth
jay
datvo06



Joined: 22 Feb 2014
Posts: 6

View user's profile Send private message

PostPosted: Sun Feb 23, 2014 9:05 am     Reply with quote

the module is from an asian site:
http://banlinhkien.vn/goods-1893-module-rf-si4432-1000m.html#.UwoMT38aySM
It's mentioned here as well
http://www.electrodragon.com/w/SI4432_433M-Wireless_Transceiver_Module_(1.5KM_Range,_Shield-Protected)
I believe it's called RF22. Yes, My Pic running at 5V and the module is running at 3.3v too...And yes the the pic pass the 1Hz Led on/off... I still don't know what the problem.
I'm using 20Mhz crystal with pic18f2550. Shocked
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Feb 23, 2014 10:41 am     Reply with quote

It is NEVER good idea to run PIC at 5 V with a 3V external device!
The PICs SPI pins are Schmitt Trigger types and require an input of 80% Vdd(.8 * 5) and that's 4 volts. There is NO way your RF module, running at 3 volts can supply a 'high' logic level.
You can use the Low voltage version of that PIC (PIC18LF2550) and correctly interface with your RF module or you can run that PIC and the rf module from 3 volts.
Check with the datasheet to be sure you can run the PIC at 20MHz at 3 volts though.

hth
jay
datvo06



Joined: 22 Feb 2014
Posts: 6

View user's profile Send private message

PostPosted: Sun Feb 23, 2014 10:52 am     Reply with quote

I got it now!
because the voltage level isn't enough so the pic can't receive signal from Module.on the other It can still be able to write to module register cause 5V is more than enough...That's why TX still working,but I can't receive anything...and that's why I got the wrong nIRQ low signal,because it's always recognized as low.
Thanks very much Very Happy ,I'll try again and post the result.
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Sun Feb 23, 2014 11:02 am     Reply with quote

Look at this thread:

<http://www.ccsinfo.com/forum/viewtopic.php?t=51955>

Look at my reply about SPI voltages.
Same applies to your project...

I see you have just 'got the point', while I posted.

The same answer I gave will also apply to you. Use a logic IC that has 'TTL' compatible inputs, and suitable voltage dividers (to avoid damaging the 3.3v chip), to get round the problem.
datvo06



Joined: 22 Feb 2014
Posts: 6

View user's profile Send private message

PostPosted: Sun Feb 23, 2014 11:57 am     Reply with quote

Rolling Eyes thanks guys
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group