View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 10, 2009 12:22 pm |
|
|
CCS combines the 7-bit i2c slave address and the R/W bit into one byte.
So in the CCS world, the slave address is shifted to left by one bit.
In the Philips world, an i2c slave address consists of 7 bits, and is not
shifted. It's right justified.
This is entirely an issue of representation, and manner of thinking.
It could also be an issue of interpretation by your logic analyzer's
protocol analyzer. An i2c slave address of 0x61 in Philips format, is
0xC2 in CCS format. |
|
|
Armer175
Joined: 13 Jan 2009 Posts: 12
|
|
Posted: Tue Mar 10, 2009 7:33 pm |
|
|
I did connect some servos to the controller later and it was working correctly. Just goes along with what you were saying about the W/R bit. Thanks again PCM Programmer |
|
|
Armer175
Joined: 13 Jan 2009 Posts: 12
|
New Problem |
Posted: Wed Mar 11, 2009 12:47 pm |
|
|
I am now having some problems reading from the spi device(ADIS16350)
datasheet:
http://www.analog.com/static/imported-files/data_sheets/ADIS16350_16355.pdf
I want to read in the "supply out" out register (pg14). But Iam not getting correct data out. I dont think i am reading the register correctly. PLEASE Help.
Code: |
While(1)
{
Output_Low(PIN_E7);
Spi_Write2(0x03); //send out address to read from
SUPPLY_OUT_HIGH=SPI_READ2(0); //read highbyte
Output_High(PIN_E7);
//DELAY_MS(10);
Output_Low(PIN_E7);
Spi_Write2(0x02);
SUPPLY_OUT_LOW=SPI_READ2(0); //read lowbyte
Output_High(PIN_E7);
SUPPLY_OUT=MAKE16(SUPPLY_OUT_HIGH, SUPPLY_OUT_LOW); //combine highbyte and lowbyte
BIT_CLEAR(SUPPLY_OUT,15&14&13&12); //cleart top bits that are not needed.
voltage=SUPPLY_OUT*1.8315e-3; //calculate voltage
fprintf(UART1,"total %lx voltage %2.5f \r\n",SUPPLY_OUT, voltage);
//servocontrol();
DELAY_MS(1000);
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 11, 2009 2:09 pm |
|
|
You need to write a driver for the ADIS16350 chip.
It needs to be written as a separate file, named ADIS16350.c.
It should have functions to read and write to the chip.
You need to try to write the ADIS16350 driver by yourself,
and if you have problems then start a new thread about it.
Here is a thread on another ADIS chip, where I have explained how
to setup the correct SPI mode.
http://www.ccsinfo.com/forum/viewtopic.php?t=38016&start=5
Do not add your questions onto that thread.
Look at this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=38131
Notice my suggestions on how to clean up the code.
Quote: | BIT_CLEAR(SUPPLY_OUT,15&14&13&12); |
This is an invention by you. Never do this. We will spot it immediately.
The CCS manual says you may use a single number, from 0 to 31
for that parameter. It's just wasting our time if you invent things.
Quote: | bit_clear( )
Syntax: bit_clear(var, bit)
Parameters: var may be a any bit variable (any lvalue)
bit is a number 0-31 representing a bit number, 0 is the least significant bit. |
Quote: | SUPPLY_OUT_LOW=SPI_READ2(0); |
Don't use ALL CAPS for functions and variables. It's not the C standard.
Use lower case or mixed case. |
|
|
Armer175
Joined: 13 Jan 2009 Posts: 12
|
|
Posted: Wed Mar 11, 2009 3:22 pm |
|
|
Is there an advantage to using a driver file other than making the main look cleaner? I was going to create seperate functions outside the main.
I haven't programmed in C for a long time so its been rough trying to write nice code. Thanks again for your help! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 11, 2009 3:51 pm |
|
|
The driver file allows you to create your own personal library of known-
good, working drivers. You can just "drop" the driver into a new project
(with an #include statement) and you know it works. |
|
|
|