| Author |
Message |
|
|
Posted: Aug 03, 2011 - 10:30 AM |
|

Joined: Jul 04, 2011
Posts: 5
|
|
Hello everyone. I'm Alberto, and i'm very very new on programming and working with AVR.
I'm doing my Master Thesis, and I have a lot of doubts.
I work with a XMEGA128a1 as microcontroller and in my board I have one LTC1400 (ADC) conected to SPIC, one AD5412 (DAC) conected to SPID and one MAX186 (ADC) conected to SPIE.
I've configured AD5412 correctly (I think) but rigth now I'm trying to comunicate with LTC1400 and read the conversion info trough the SPI BUS.This is the pin conection: CONV to MOSI (PIN5), DOUT to MISO (PIN6) and CLK to CLK (PIN7). The problem is that I don't know how to read the info from the LTC. It suppous that I must put high CONV pin, and with the CLK signal working the conversion and transmission starts, but I can't have the CLK pin in XMEGA working. I've configured the SPIC as master.
I hope I explained ok. Thanks and sorry for my English.
Alberto. |
|
|
| |
|
|
|
|
|
Posted: Aug 03, 2011 - 10:55 AM |
|


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
The problem is that I don't know how to read the info from the LTC.
In SPI you have a Master and a Slave. For something like an ADC the Xmega will be the Master and the ADC will be the Slave. The Slave can NEVER instigate a data transfer on its own. The SPI bus only generates clock pulses when the Master transmits something. This means that to "read" the Slave ADC the Xmega master actually has to send a byte or two (depending how many the ADC plans to return). The ADC itself will likely ignore the actual data bytes that are being sent as they're only being send to initiate the transfer as such they are often called "dummy" or "stuffing" bytes. |
_________________
|
| |
|
|
|
|
|
Posted: Aug 03, 2011 - 12:42 PM |
|

Joined: Jul 04, 2011
Posts: 5
|
|
|
Quote:
In SPI you have a Master and a Slave. For something like an ADC the Xmega will be the Master and the ADC will be the Slave. The Slave can NEVER instigate a data transfer on its own. The SPI bus only generates clock pulses when the Master transmits something. This means that to "read" the Slave ADC the Xmega master actually has to send a byte or two (depending how many the ADC plans to return). The ADC itself will likely ignore the actual data bytes that are being sent as they're only being send to initiate the transfer as such they are often called "dummy" or "stuffing" bytes.
Thank you for your answer.
The problem is that I can not send some bytes to the ADC because the pin MOSI is conected to the pin CONV of the ADG and in the initialization of SPI modul on port C this pin is put to High, and that means to the ADC start the conversion, and I can only send only one change to 0 in this CONV PIN. So I don't know if it's going to work, but I will try.
Thanks. |
|
|
| |
|
|
|
|
|
Posted: Aug 03, 2011 - 12:46 PM |
|


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
| The reason you are sending stuffing/filler bytes is ONLY so the SPI starts to pulse the SCK line - whether MOSI is actually connected from the AVR to the slave does not actually matter as the slave is unlikely to be interested in the actual data bytes anyway (unless the LTC has some "commands" that allow you to configure it?) |
_________________
|
| |
|
|
|
|
|
Posted: Aug 29, 2011 - 07:15 PM |
|

Joined: Jul 04, 2011
Posts: 5
|
|
|
clawson wrote:
The reason you are sending stuffing/filler bytes is ONLY so the SPI starts to pulse the SCK line - whether MOSI is actually connected from the AVR to the slave does not actually matter as the slave is unlikely to be interested in the actual data bytes anyway (unless the LTC has some "commands" that allow you to configure it?)
Sorry to answer so late but I was focus in another parts of my potentiostat.
I tried to write in DATA register one byte of zeros and send it and then read the DATA register.Now I send another byte of zeros and I read the DATA register another time, but the result is not good, because I must keep the CONV line (MOSI pin) always down till the conversion is finished, and between both bytes of zeros the pin goes up.
I did it manually, generatin the clock cycle in pin 7 and reading in each clock cycle the MISO line. Is not the best way but I don't know how to do it.
Thank you very much for your help. |
|
|
| |
|
|
|
|
|
Posted: Aug 30, 2011 - 06:35 AM |
|

Joined: Mar 30, 2008
Posts: 51
Location: Perth, WA, Australia
|
|
@Alberto,
I'd really recommend you read the XMega A Manual, in particular the SPI section, and get yourself familiar with SPI in general before asking questions here.
It sounds to me like you're trying to attach MOSI to a pin which has an unrelated function, possibly what is referred to as _SS (Slave Select) in SPI terminology.
You should set CONV independently using a free PIN, then wait a suitable time for the sample to complete, and then initiate an SPI read/write two bytes long by sending two blank bytes, and then massage your result to get the 12Bit result.
If you're not trying to send "data" to the device you probably don't even need to wire MOSI from the XMega device to anything on the slave IC.
Euan. |
|
|
| |
|
|
|
|
|
Posted: Aug 30, 2011 - 03:44 PM |
|

Joined: Jul 04, 2011
Posts: 5
|
|
|
edekock wrote:
@Alberto,
I'd really recommend you read the XMega A Manual, in particular the SPI section, and get yourself familiar with SPI in general before asking questions here.
It sounds to me like you're trying to attach MOSI to a pin which has an unrelated function, possibly what is referred to as _SS (Slave Select) in SPI terminology.
You should set CONV independently using a free PIN, then wait a suitable time for the sample to complete, and then initiate an SPI read/write two bytes long by sending two blank bytes, and then massage your result to get the 12Bit result.
If you're not trying to send "data" to the device you probably don't even need to wire MOSI from the XMega device to anything on the slave IC.
Euan.
You are right.
I discovered it in all this time that the problem is mine. I connected the MOSI Pin to the "SS" pin of the LTC (is not the SS pin really but makes the same function). But I can not change because the PCB is made so this change must be applied in future versions of the PCB. jejej.
My works ends here.
Thank you. |
|
|
| |
|
|
|
|
|
Posted: Aug 31, 2011 - 03:22 AM |
|

Joined: Mar 30, 2008
Posts: 51
Location: Perth, WA, Australia
|
|
Bad Luck re the PCB but at least you know the solution now.
That's what breadboards are for...
Regards,
Euan. |
|
|
| |
|
|
|
|
|