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 Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
littlephoc



Joined: 12 Dec 2006
Posts: 8

View user's profile Send private message

PostPosted: Thu Dec 28, 2006 11:46 pm     Reply with quote

I am using CCS 4.016
Code:
 //file cc1000.h
/* Register addresses */

#define CC1000_MAIN            0x00
#define CC1000_FREQ_2A         0x01
#define CC1000_FREQ_1A         0x02
#define CC1000_FREQ_0A         0x03
#define CC1000_FREQ_2B         0x04
#define CC1000_FREQ_1B         0x05
#define CC1000_FREQ_0B         0x06
#define CC1000_FSEP1           0x07
#define CC1000_FSEP0           0x08
#define CC1000_CURRENT         0x09
#define CC1000_FRONT_END       0x0A
#define CC1000_PA_POW          0x0B
#define CC1000_PLL             0x0C
#define CC1000_LOCK            0x0D
#define CC1000_CAL             0x0E
#define CC1000_MODEM2          0x0F
#define CC1000_MODEM1          0x10
#define CC1000_MODEM0          0x11
#define CC1000_MATCH           0x12
#define CC1000_FSCTRL          0x13
#define CC1000_FSHAPE7         0x14
#define CC1000_FSHAPE6         0x15
#define CC1000_FSHAPE5         0x16
#define CC1000_FSHAPE4         0x17
#define CC1000_FSHAPE3         0x18
#define CC1000_FSHAPE2         0x19
#define CC1000_FSHAPE1         0x1A
#define CC1000_FSDELAY         0x1B
#define CC1000_PRESCALER       0x1C
#define CC1000_TEST6           0x40
#define CC1000_TEST5           0x41
#define CC1000_TEST4           0x42
#define CC1000_TEST3           0x43
#define CC1000_TEST2           0x44
#define CC1000_TEST1           0x45
#define CC1000_TEST0           0x46

#define  LOCK_NOK         0x00
#define  LOCK_OK          0x01
#define  LOCK_RECAL_OK    0x02

// Value of time-out timer during calibration
#define CAL_TIMEOUT   0x7FFE
#define LOCK_TIMEOUT  0x7FFE


/************************************/
//TX Register configuration define:
/************************************/
#define MAIN_TX         0xE1 //11100001
#define MAIN_RX         0x11
#define MAIN_PD          0x7F


and my library.h:
Code:

//file mylib.h
#byte SSPBUF  =  0x0FC9
#byte SSPSTAT =  0x0FC7
#byte SSPCON1 =  0x0FC6
#byte SSPCON2 =  0x0FC5
#byte trisC  = 0x0F94
#byte adcon2 = 0x0FC0
#byte adcon1 = 0x0FC1
#byte adcon0 = 0x0FC2
#byte portA  = 0xF80
#byte portB  = 0xF81
#byte PortC  =  0x0F82

#bit DCLK = PortC.0
#bit DIO  = PortC.1
#bit PALE = PortC.2
#bit PCLK = PortC.3
#bit PDATA_IN=PortC.4
#bit PDATA_OUT= PortC.5
#bit TRIS_OUT = trisC.5
#bit DIO_DIR = trisC.1
#bit BF = SSPSTAT.0
#bit SSPOV = SSPCON1.6
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 29, 2006 1:50 am     Reply with quote

It looks like you translated the sample routines OK. I'm not sure why
it doesn't work. I saw two things in your code that are incorrect.
You don't need the SPI_SS_DISABLED constant. It's only used in SPI
slave mode. You're using master mode. You can delete it.
Also you should have a while(1); statement at the end of main(), to
avoid putting the PIC in Sleep mode. The compiler puts a hidden SLEEP
instruction at the end of main().

We may have a CC1000 Development kit in the storage closet.
I know we have a CC2400 kit, and one other kit. I'll look for it
tomorrow. If we have it, then maybe I can give some more help.

One thing that I have a question about, is do we know that the TEST3
register is fully readable and writable ? Normally a data sheet will
say if a register is R/W or R/O (read only). I don't see that description
in this data sheet. So, there is some doubt in my mind about it.
Quote:

void main()
{
int data;
set_tris_c(0x13); //00010011
setup_spi(SPI_MASTER |SPI_H_TO_L |SPI_CLK_DIV_16 | SPI_SS_DISABLED);
data=0;
cc1000_reset();
cc1000_write_register(CC1000_TEST3,0x59);
data =cc1000_read_register(CC1000_TEST3);

while(1);
}



Edited to add:
I checked the storage room, and we don't have a CC1000 dev kit.
It's a CC1010 kit. It doesn't have the same 3-wire interface as the
CC1000. So I'm not sure if I can help you much more. If I think of
anything, I'll post it here.
littlephoc



Joined: 12 Dec 2006
Posts: 8

View user's profile Send private message

PostPosted: Wed Jan 24, 2007 11:23 pm     Reply with quote

Dear PCM programmer
I post my code here. It works. I am sorry because I posted it in another topic cause I was mistake of the login to this forum.


Code:
//file cc1000.c
void WriteToCC1000Register(char address, char data)
{
   char dummy;
   char addr;
   output_low(PIN_PALE);
    shift_left(&address,1,1);
    dummy =SSPBUF;
   spi_write(address);
   output_high(PIN_PALE);
   spi_write(data);
}

char ReadFromCC1000Register(char addr)
{
   char value;
   PALE=0;
   value=SSPBUF; //dummy read
   value=addr;
   shift_left(&value,1,0); //read bit is 0
   spi_write(value);
   PDATA_OUT=1;
   trisC |=0x20; //switch direction
   PALE=1;
   spi_write(0xFF);
   value=spi_read();
   trisC &=~0x20;
   return value;
}

void cc1000_reset()
{
   char mainvalue;
   mainvalue=ReadFromCC1000Register(CC1000_MAIN);
   WriteToCC1000Register(CC1000_MAIN,mainvalue & 0xFE);         // Reset CC1000
   WriteToCC1000Register(CC1000_MAIN,mainvalue | 0x01);         // Bring CC1000 out of reset
}   
void SetupCC1000PD(void)
{
  WriteToCC1000Register(CC1000_MAIN,0x3F);    // Put CC1000 into power-down
  WriteToCC1000Register(CC1000_PA_POW,0x00);  // Turn off PA to minimise current draw
}


Code:
//file main.c
#include <18Fxxxx.h>
#include "cc1000.h"
#include "mylib.h"

#fuses HS,NOWDT,NOPROTECT,LVP 
#use delay(clock=8000000)
#use SPI(DO=PIN_C5,DI=PIN_C4,CLK=PIN_C3,BITS=8)
// PA power setting
#define PA_VALUE 0xF0
#include "cc1000.c"
void main(void)
{
   char dummy;
   PORTC=0x00;
   TRISC=0x92;
   setup_spi(SPI_MASTER |SPI_H_TO_L |SPI_CLK_DIV_4); //5ns

//----------------------------------------------------   
   SetupCC1000PD();
   cc1000_reset();
      while(1){
        cc1000_write_register(CC1000_MAIN,0xA1);
        dummy =cc1000_read_register(CC1000_MAIN);
      }
   }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 25, 2007 12:36 am     Reply with quote

If you believe this is good code, then post it in the Code Library forum
as a Chipcon CC1000 driver. Also post the CCS compiler version and
the PIC that you used to test the driver.
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 Previous  1, 2
Page 2 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