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 support@ccsinfo.com

I2C 12bit package

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



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

I2C 12bit package
PostPosted: Thu Feb 09, 2012 2:11 pm     Reply with quote

Hi!
How can I send 12bit package data with I2C Bus.
My purpose is to drive serial input DAC8512(12bit).
Is that piece of code could be useful?


Code:

unsigned long data=8192;
i2c_start();
i2c_write(data);
i2c_stop();


Excuse my bad english!
Thx. in advance!
temtronic



Joined: 01 Jul 2010
Posts: 9165
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Feb 09, 2012 3:11 pm     Reply with quote

You need to create a 'driver' for that I2C device if none exist.
Study the datasheet for the device and read what it requires in setup and writing to the device.At the very least you'll need to send it 2 bytes worth of data,perhaps more.The details will be in the datasheet.
Ttelmah



Joined: 11 Mar 2010
Posts: 19348

View user's profile Send private message

PostPosted: Thu Feb 09, 2012 3:49 pm     Reply with quote

Seriously though I2C _as a standard_, handles 8bit data _only_. Devices that need odd sizes of data usually allow it to be sent as two 8bit bytes, with extra zeros at the start or end.
You can't expand I2C, to handle 12bit, without getting into problems with device addressing.

The DAC8512, does not use I2C, but SPI, with a CS signal. The hardware SPI can't do this, but the CCS standard SPI library can.

Best Wishes
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Fri Feb 10, 2012 2:22 am     Reply with quote

The datasheet for the DAC8512 states (On page 14) that it latches the 12 bit data on the negatvie going edge of /LD and puts the voltage on the output. It also ignores any further clocks until you reenable /CS. THis means that you have to arrange things so that the right data is in its shift register when you activate /LD.

So simply send it two bytes by SPI, right justifying the 12 bit data, in other words theupper nibble of the first byte is zero padding and the 4 most significant bits, the second byte is the least significant 8 bits. I.e. 12 bits in two bytes, right justified & padded with zeros. Simples.

You must control the select for the IC correctly, as it uses that to determine when new data is being sent. So, what you do each time you send to the DAC is:

Enable CS (set it to 0)
Send, using SPI, upper four bits as zero (or anything, they are ignored so ti doesn't matter what they are), lower 4 bits are the most significant 4 bits of the data
Send least significant 8 bits using SPI.
Disable CS (set to 1)
Enable LD (set to 0) (DAC output changes here)
LD must be held low for at least Tldw min, or 20ns. One instruction of even the fastest PIC is fine, so there's no need for any extra delay.
Disable LD(set to 1)


RF Developer
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Fri Feb 10, 2012 12:15 pm     Reply with quote

I reviewed the timing diagram in datasheet and I understood what you did mean. I will attempt with SPI. I hope its going to work.
Thank you guys!
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