bocek06
Joined: 21 Jul 2006 Posts: 1
|
reading from & writing to cc1000 registers |
Posted: Wed Aug 02, 2006 4:12 am |
|
|
Hi all!
i m currently trying writing to & reading from cc1000
> registers by using the 3-wire configuration.I ve used the
> implementation interface written for the IAR PIC16 compiler that i ve
> downloaded from microchip's website n tried to adapt it to use with the
> msp430x149 mcu. i ve rewritten the code which was already written for IAR PIC16 .What i don t understand at this point about this 3-wire configuration is that for the write function
" WriteToCC1000RegisterWord(short addranddata)" by using this 3-wire configuration we only change the value of the pdata pin either to 0 or to 1 but doesn't load any addr or data value to anywhere or maybe i didn't understand.So then as no addr and data value is kept in anywhere,when we try to read a register's value "ReadFromCC1000Register(char addr) " what the code does is only to look at pdata's current pin value which is either a 1 or a 0 n then
setting the return value's pins "called Read_Data in my code" correspondingly.So in the code portion ;
for (BitCounter=0;BitCounter<8;BitCounter++)
{
P4OUT &= ~1 ;
//PCLK=0;
Read_Data= Read_Data<<1;
if(P4IN & 0x02==0x02) //if pdata high sa
{
print("pin high\n");
Read_Data |= 0x01;
}
else
{
print("pin low\n");
Read_Data &= 0xfe;
}
P4OUT |= 1 ;
//PCLK=1;
}
what it does is to set all 8 bits of Readdata( the variable i m gonna return from the ReadFromCC1000Register(char addr) function ) to 1 as the last value of PDATA was just a 1.So i feel like i really don t understand how this 3-wire configuration works as i can t figure out where all addr n data information is kept when we make a write.At the
data_sheet for CC1000 so called CC1000_Data_sheet_2.3 -reached by the following url "www.chipcon.com/files/CC1000_Data_Sheet_2_3.pdf" - it says all these addr and data bits are sent over PDATA pin but sent where? from where i can reach them when i wanna read that register's value.Again in the datasheet it says data is loaded in the internal register but i couldn t figure out and find anywhere what that internal register is.it means PDATA??
below is the complete code i ve used for writing to or reading from cc1000 registers;
/****************************************************************************/
/* This routine sends new configuration data to the CC1000 */
/****************************************************************************/
void ConfigureCC1000(short Count, short Configuration[])
{
short val;
short i;
for (i=0;i<Count;i++) {
val=Configuration[i];
WriteToCC1000RegisterWord(val);
}
}
/****************************************************************************/
/* This routine writes to a single CC1000 register, with address and data */
/* given in the same variable */
/****************************************************************************/
void WriteToCC1000RegisterWord(short addranddata)
{
char BitCounter;
unsigned short MSB;
//PALE=1;
P4OUT |=4 ;
print("16 bitlik val sole : %hd\n",addranddata);
unsigned short Data = addranddata ; //16 bit
print("union imdaki data sole : %hd\n",Data);
P4OUT &= ~4 ;
//PALE=0;
//set PDATA as output- not: output 0 diye assume ettim
P4DIR &= ~2 ;
// Send address bits
for (BitCounter=0;BitCounter<7;BitCounter++) // 7 kere shift
{
P4OUT |= 1;
//PCLK=1;
MSB= Data & 0x8000 ;
if(MSB) //MSB 1 ken
{
print("check...msb high?\n");
IF_HIGH ;
}
else
IF_LOW;
print("data write da shift edilmeden once : %hd\n",Data);
Data=Data<<1;
print("data write da shift edildikten sonra : %hd\n",Data);
P4OUT &= ~1 ;
//PCLK=0;
}
// Send read/write bit
// Ignore bit in data, always use 1
P4OUT |= 1;
//PCLK=1;
P4OUT |= 2;
//PDATA=1;
P4OUT &= ~1;
//PCLK=0;
Data=Data<<1;
print("data write da bi daha shift edildikten sonra : %hd\n",Data);
P4OUT |= 1;
//PCLK= 1
P4OUT |= 4;
//PALE=1
// Send data bits
for (BitCounter=0;BitCounter<8;BitCounter++)
{
P4OUT |= 1;
//PCLK=1;
MSB=Data & 0x8000 ;
if(MSB) //if high
{
print("high iim benn!! \n");
IF_HIGH ;
}
else
IF_LOW;
Data=Data<<1;
print("data write da loopda son shift edilikten sonra : %hd\n",Data);
P4OUT &= ~1 ;
//PCLK=0;
}
P4OUT |= 1 ;
//PCLK=1;
}
/****************************************************************************/
/* This routine reads from a single CC1000 register */
/****************************************************************************/
char ReadFromCC1000Register(char addr)
{
char BitCounter;
unsigned char Read_Data;
unsigned char Read_MSB;
//8 bit values
print("read fonkundayim su an\n");
P4OUT |= 4 ;
// PALE=1;
Read_Data=addr<<1;
print("read data su addr bi kere kaydi : %d\n",Read_Data);
P4OUT &= ~4;
//PALE=0;
//set PDATA a output
P4DIR &= ~2;
// Send address bits
// pinar: burda 8 bitlik bir degeri 8 kere kaydirirsak o deger her zaman 0 olmaz
mi??
for (BitCounter=0;BitCounter<7;BitCounter++)
{
P4OUT |= 1;
//PCLK=1;
Read_MSB= Read_Data & 0x80 ;
if(Read_MSB) //if high
{
print("read yapiorm ve high im ben:)\n");
IF_HIGH ;
}
else
IF_LOW;
print("read data shift edilmeden once okunurken su : %d\n" ,Read_Data );
Read_Data= Read_Data<<1;
print("read data shift edildikten sonra okunurken su : %d\n" ,Read_Data );
P4OUT &= ~1 ;
//pinler 1 den baslio unutma!! PCLK=0;
}
// Send read/write bit
// Ignore bit in data, always use 0
//PCLK=1;
P4OUT |= 1;
P4OUT &= ~2 ;
P4OUT &= ~1 ;
//PDATA=0;
//PCLK=0;
P4OUT |= 1 ;
P4OUT |= 4 ;
//PCLK=1;
//PALE=1;
// Receive data bits
//bunu neden yapio bilmiorm gercekten ama pdata 1 oluo
P4OUT |= 2;
P4DIR |= 2;
// set up PDATA as an input 0
print("bu noktada Read_data nin 0 olmasi lazim bence ama su : %d\n" ,Read_Data );
//pinar: bu loop neden donuo anlamis diilim zaten Read_Data dedigimiz deger 8 bit diil
mi??
for (BitCounter=0;BitCounter<8;BitCounter++)
{
P4OUT &= ~1 ;
//PCLK=0;
Read_Data= Read_Data<<1;
if(P4IN & 0x02==0x02) //if pdata high sa
{
print("pin high\n");
Read_Data |= 0x01;
}
else
{
print("pin low\n");
Read_Data &= 0xfe;
}
P4OUT |= 1 ;
//PCLK=1;
}
P4DIR &= ~2;
//TRISC&=~0x20; Set up PDATA as an output 1 again
return Read_Data;
}
///////////////////////MAIN
int main()
{
initPorts();
// initializes the ports of the MSP430F149
initClock();
System_setDCO(); // setup DCO (digital controlled oscillator)
initUART(BPS_115200); // initialize UART for serial communication
char value;
//check to see if writing n reading from cc1000 regs works
ConfigureCC1000(1,DefaultConfig433);
value=ReadFromCC1000Register(0x01);
print("the value at pdata equals : %d",value);
print("return from main\n");
return 0;
}
That s all i wanna ask to you.Hope that anyone can take the time to look at it as i really got stuck on this point n need help
thanks for your consideration
regards
Pinar |
|