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

PIC18F8723 Setup

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 10, 2009 12:22 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 10, 2009 7:33 pm     Reply with quote

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 Smile
Armer175



Joined: 13 Jan 2009
Posts: 12

View user's profile Send private message

New Problem
PostPosted: Wed Mar 11, 2009 12:47 pm     Reply with quote

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);   
   
   }

Confused
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 11, 2009 2:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 11, 2009 3:22 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 11, 2009 3:51 pm     Reply with quote

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.
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