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

chipcon cc1000 ccs code
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dan king



Joined: 22 Sep 2003
Posts: 119

View user's profile Send private message

chipcon cc1000 ccs code
PostPosted: Wed Apr 07, 2004 12:30 pm     Reply with quote

Has anyone successfully coded a project for the CC1000 rf transceiver from Chipcon? I'm attempting the migration of the suppplied IAR C code to ccs C, but am running into many difficulties. Any help would be appreciated.

Shocked
mjscott
Guest







Chipcon
PostPosted: Wed Apr 07, 2004 12:35 pm     Reply with quote

Don't you mean CC1010 the 8051 core? If that is what you are speaking of we have completed a number of project but only using the Kiel compiler
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 07, 2004 12:44 pm     Reply with quote

We've used Chipcon product, not the CC1000, but another one.
We ported their sample Keil code without too many problems.

If you go to their website, and click on Downloads, and then
on CC1000, they show AN009 source code available.
The zip file contains cc1000pic.c and cc1000avr.c, etc.
I haven't worked with that specific code, but if you can
tell me a routine that's giving you problems, I could look at it.
Tell me the specific problems (compile errors, etc.) that you're seeing.
dan king



Joined: 22 Sep 2003
Posts: 119

View user's profile Send private message

PostPosted: Wed Apr 07, 2004 12:56 pm     Reply with quote

for starters, I'm fairly new with C and the following use of a struct and a union at the same time has caused me some troubles trying to port the functionality.
Code:

void WriteToCC1000RegisterWord(short addranddata)

union {     // This union is used to easily access the most significant
              // bit of the configuration data
             
              // Note : This assumes that the C compiler stores bit-fields
              // with the first field going into the LSB. If this is not the
              // case, move the MSB definition to the first bit
    unsigned short Data;
    struct
    {
      unsigned short :1;
      unsigned short :1;
      unsigned short :1;
      unsigned short :1;
      unsigned short :1;
      unsigned short :1;
      unsigned short :1;
      unsigned short :1;
      unsigned short :1;
      unsigned short :1;
      unsigned short :1;
      unsigned short :1;
      unsigned short :1;
      unsigned short :1;
      unsigned short :1;
      unsigned short MSB :1;
     };
  };
 
  PALE=1;

  Data=addranddata;
  PALE=0;
   
  // Send address bits
  for (BitCounter=0;BitCounter<7;BitCounter++)
  {
    PCLK=1;
    PDATA_OUT=MSB;


I understand that the union will share memory with the included variables, kind of overlap. The ref code then uses MSB as a direct access point to the most sig bit. I just can't get the compiler to "like" any attempts.

Also, why is their passed variable of type short when it appears to be 16bit int?

Thanks for the help Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 07, 2004 2:10 pm     Reply with quote

I found that routine in their sample code. I will get back to
you on it later today (by midnight), if someone else doesn't
help you first. I have beaucoup work today at the company.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 07, 2004 9:43 pm     Reply with quote

To modify that routine for CCS, the easiest way is to get rid of
the union and structure, and just use the #bit directive.
See the changes that I have done near the start of the
WriteToCC1000RegisterWord() function, below.

When you modify the IAR compiler code to work with CCS, you
should know that in IAR a "short" is a signed 16-bit value.
I looked at the places where the sample driver uses
"short", and I think you can safely use the CCS "int16"
as substitute. Int16 is an unsigned 16-bit value in CCS.
You can see that I've done that with the "Data" variable, below.

---------------------------------------------------------
Code:

// This is a test program, to check modifications to the
// WriteToCC1000RegisterWord() function.

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

// Define the control signals as bits 0, 1, and 2 on Port B.
// (Just for this test).
#byte PortB = 6
#bit  PALE = PortB.0
#bit  PCLK = PortB.1
#bit  PDATA_OUT = PortB.2

void WriteToCC1000RegisterWord(int16 addranddata);

//===========================================
void main()
{
int16 value;

WriteToCC1000RegisterWord(value);

while(1);

}

//===========================================

void WriteToCC1000RegisterWord(int16 addranddata)   // 4-7-04 Changed to int16 (was short)
{
  char  BitCounter;
  int16 Data;                // 4-7-04  Changed to int16  (was short)
  #bit  MSB = Data.15        // 4-7-04  Removed union.  Added #bit statement
 
  PALE=1;

  Data=addranddata;
  PALE=0;
   
  // Send address bits
  for (BitCounter=0;BitCounter<7;BitCounter++)
  {
    PCLK=1;
    PDATA_OUT=MSB;
    Data=Data<<1;
    PCLK=0;
  }
  // Send read/write bit
  // Ignore bit in data, always use 1
 
  PCLK=1;
  PDATA_OUT=1;
  PCLK=0;
  Data=Data<<1;
  PCLK=1;
  PALE=1;
   
  // Send data bits
 
  for (BitCounter=0;BitCounter<8;BitCounter++)
  {
    PCLK=1;
    PDATA_OUT=MSB;
    Data=Data<<1;
    PCLK=0;
  }
  PCLK=1;
}
dan king



Joined: 22 Sep 2003
Posts: 119

View user's profile Send private message

PostPosted: Thu Apr 08, 2004 6:26 am     Reply with quote

Thanks for all of your help!! That makes more sense than some of the changes I was trying to make, none of which worked.

I had started replacing all of the short type with int16, I'm glad you agree this looks valid. I hope this didn't take too much time away from your existing workload.

Best regards,

Dan
littlephoc



Joined: 12 Dec 2006
Posts: 8

View user's profile Send private message

PostPosted: Tue Dec 19, 2006 8:44 am     Reply with quote

Quote:
for (BitCounter=0;BitCounter<7;BitCounter++)
{
PCLK=1;
PDATA_OUT=MSB;
Data=Data<<1;
PCLK=0;
}

There is a buffer register for read/write data. Please explain why you have to use this code?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 19, 2006 12:51 pm     Reply with quote

Download the Chipcon sample driver code for the CC1000:
http://www.chipcon.com/files/AN_009_source_code_3_3.zip
Look in the file called cc1000pic.c, and find the function called
WriteToCC1000RegisterWord().

This is Chipcon's example of how to write a word to the CC1000
from a PIC.

The routine that I posted earlier in this thread was an example
of how to "port" (i.e., to change) source code from the IAR compiler
to the CCS compiler. If your goal is to create a driver as soon as
possible, then one way to do it, is to port the existing driver to CCS
and make as few changes as possible. Don't try to invent anything
new. That was the purpose.

It's true that the sample IAR driver uses bit-banging to do the SPI
in that routine. If you want to change the code to use the hardware
SPI module in the PIC, then you can do so. But sometimes it's a
good idea to first get a working driver very quickly, so you can
demonstrate your prototype board. In that case, you would just do
a quick port of the IAR code as I described above.

Also, while reviewing the code that I wrote above, I noticed a bug.
I'm doing direct i/o to port pins, but I don't have a TRIS statement
to set those pins to be outputs.
This statement should be added at the start of main().
Code:
// Set PortB pins B0, B1, B2 as outputs.
set_tris_b(0xF8); 

Also, this statement should be placed above main():
Code:
#use fast_io(B)
littlephoc



Joined: 12 Dec 2006
Posts: 8

View user's profile Send private message

PostPosted: Wed Dec 27, 2006 6:26 am     Reply with quote

Dear PCM programmer
I have made some effort to port this code to CCS. but now I have a problem:
the read/write function is not work correctly. because MISO and MOSI pin are connect together to PDATA pin of CC1000.
while use SPI hardware function, I always receive 00000001 when I use read_cc1000_register()
by using bit bagging, I receive 0xFF value return from read_cc1000_register() function.
Could you please show me something that I am wrong? I think it's no problem for me to write CCS code. I will post my CCS code of your suggest.[/img]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 27, 2006 1:28 pm     Reply with quote

I didn't realize that the CC1000 only has one pin for data i/o. It uses
a 3-wire bus. My experience is with the CC2400, which has a 4-wire bus.

However, in the Chipcon example file, cc1000pic.c, they show how to
use the hardware SPI module in a 16F876 with the CC1000.
The cc1000pic.c source file can be downloaded here:
http://www.chipcon.com/files/AN_009_source_code_3_3.zip

Go to line 162 in that file. You'll find this function:
Code:
char ReadFromCC1000Register(char addr)


It has this code:
Code:
// Switch direction
  PDATA_OUT=1;
  TRISC|=0x20; // Set up PDATAOUT as an input

The code above changes the SDO pin (pin C5) into an input, during
a receive operation, by setting the TRISC.5 bit = 1.

That's how they handle the 3-wire interface, where the SDO and SDI
pins are connected together.

You need to write your code to do something similar to the sample code.
littlephoc



Joined: 12 Dec 2006
Posts: 8

View user's profile Send private message

PostPosted: Wed Dec 27, 2006 10:58 pm     Reply with quote

This is the pin connection photo:
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 28, 2006 12:55 am     Reply with quote

Post a short program that shows how you read the Chipcon chip,
and also show how you setup the hardware SPI module.


When you post code, put it in a "code block" with the Code button,
and also make sure you disable HTML. There is a box below the
posting window to do this. It looks like this:
Quote:
x Disable HTML in this post
littlephoc



Joined: 12 Dec 2006
Posts: 8

View user's profile Send private message

PostPosted: Thu Dec 28, 2006 3:24 am     Reply with quote

Code:
//file cc1000.c
void cc1000_write_register(char addr, char data)
{
   char dummy;
   PALE=0;
   dummy =SSPBUF;
   SSPBUF=(addr<<1)|0x01;
   while (BF==0); //wait until data is writen
   PALE=1;
   dummy=SSPBUF;
   SSPBUF=data;
   while(BF==0);
/*   
                char spi_data;
                spi_data=SSPBUF;
   spi_data = addr;
   PCLK=1;
   PALE=0;
   shift_left(&spi_data,1,1); // addr bit is 1
   spi_write(spi_data);
   spi_data=SSPBUF;
   PALE=1;
   spi_data=SSPBUF;
   spi_data=data;
   spi_write(spi_data);
*/
}

char cc1000_read_register(char addr)
{
   char value;
   PALE=0;
   value=SSPBUF;
   value=addr;
   shift_left(&value,1,0); //read bit is 0
   //spi_write(value);
   SSPBUF=value;
   while(BF==0); //wait until data is written
   SSPOV=0;
   PDATA_OUT=1;
   trisC |=0x20; //switch direction
   PALE=1;
   SSPBUF=0xFF;  //dummy write
   while(BF==0);
   value=SSPBUF;
   trisC &=~0x20;
//   value=spi_read();
   return value;
}

//file main.c
#include <18F2620.h>
#include "cc1000.h"
#include "mylib.h"
#fuses HS,NOWDT,PUT,NOPROTECT,NOLVP
#use SPI(DO=PIN_C5,DI=PIN_C4,CLK=PIN_C3,BITS=8)
#use delay(clock=8000000)
#use fast_io(C)
#include "cc1000.c"
void main()
{
   int data;
   set_tris_c(0x13); //00010011
   setup_spi(SPI_MASTER |SPI_H_TO_L |SPI_CLK_DIV_16 | SPI_SS_DISABLED); //50ns
   data=0;
   cc1000_reset();
   cc1000_write_register(CC1000_TEST3,0x59);
   data =cc1000_read_register(CC1000_TEST3);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 28, 2006 8:20 pm     Reply with quote

Post all the declarations for:

PALE
BF
SSPBUF
TrisC
CC1000_TEST3
etc.

The code that you posted can't be compiled because all those
declarations are missing.

Also post your compiler version. I can see that you're using vs. 4.xxx,
but what is the exact version ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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