View previous topic :: View next topic |
Author |
Message |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
I2C 12bit package |
Posted: Thu Feb 09, 2012 2:11 pm |
|
|
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: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Feb 09, 2012 3:11 pm |
|
|
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: 19510
|
|
Posted: Thu Feb 09, 2012 3:49 pm |
|
|
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
|
|
Posted: Fri Feb 10, 2012 2:22 am |
|
|
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
|
|
Posted: Fri Feb 10, 2012 12:15 pm |
|
|
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! |
|
|
|