What am i doing wrong with my code?
grasshopper
Posts: 438
I am trying to read the data from an ADS8341 16 bit 4 channel A/D convertor using internal clock mode.
The data sheet states that to read from channel 1 using internal clock mode i need to send out a 8 bits 11010110
here is my code
the data sheet can be found at www.chipcatalog.com/Datasheet/2838D5B2E81B44E3DC343E2C4AAB9B9A.htm
The data sheet states that to read from channel 1 using internal clock mode i need to send out a 8 bits 11010110
here is my code
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 CS = 13 'Propeller Pin Din = 14 'Propeller Pin Dout = 15 'Propeller Pin use a resistor on this pin Clk = 12 'Propeller Pin OBJ SER[noparse][[/noparse] 3 ] : "FullDuplexSerial" pub start ser[noparse][[/noparse] 0 ].start(31, 30, 0, 9600) 'Sets up Com port (Rxpin,Txpin,mode,baud) ser[noparse][[/noparse] 1 ].start(15, 14, 0, 9600) 'Set up com from IC dira[noparse][[/noparse]CS]~~ 'sets pin as output repeat outa[noparse][[/noparse]CS]~~ 'sets pin 7 high outa[noparse][[/noparse]CS]~ 'sets pin 7 low activating the ADS8341 ser[noparse][[/noparse] 1 ].str(string("%11010110")) waitcnt (1_000_000 * 50 + cnt ) outa[noparse][[/noparse]CS]~~ 'sets pin 7 high outa[noparse][[/noparse]CS]~ 'sets pin 7 low activating the ADS8341 waitcnt (1_000_000 * 50 + cnt ) ser[noparse][[/noparse] 0 ].str(ser[noparse][[/noparse] 1 ].rx) ser.tx(13) 'line feed ser.tx(10)
the data sheet can be found at www.chipcatalog.com/Datasheet/2838D5B2E81B44E3DC343E2C4AAB9B9A.htm
Comments
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
Hum ! ill take another look
So lets make a list of the key points listed in the datasheet:
The above specifications mean that you should be using a SPI object, not FullDuplexSerial. SPI_Engine is a good choice, and so is BS2 Functions. I would highly recommend you use the internal clock for ADC conversion clock since external clocking will likely cause you more problems (like minimum 24kHz clock, etc).
Your posted code also has a few fundamental flaws that would prevent it from working even if you got the ADC communication working perfectly. To send a binary number, you would use ser.tx(%11010110) and not ser.str(...). To echo the received data to another FullDuplexSerial object, you would need a repeat block and ser1.tx(ser2.rx).
So try rewriting your code using SPI Engine and make sure you look at the clocking/data requirements for the chip. The information about when to read the data with regards to the clock rising/falling edge is extremely important.
I need to know what the following is for
What does "mode" do? and "Value"?
Can some one explain to me if i am approaching this correctly?
your "SPI Engine" object, wherever that came from.
Looks like you're on the right track though.
Here is the object i am using
Let me know what you think it is as i eagerly wait
There may be a reason that this code was not implemented into the object exchange... I only had a chance to do limited testing with a few shiftin/shiftout IC's (74HC165, and 74HC595).
It's probably just too fast for some other IC's and needs to be slowed down a bit, but I don't know that for sure.· Where I would slow it down would be in this section of code...
... by inserting NOP or delays in-between where the clock goes HIGH or LOW.
Alternatively you could try the BS2_Function library and use the SHIFTIN/SHIFTOUT routines there.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
I posted the "New" code for any one that needs to use it on a ADS8341E 16bit 4 channel A to D converter
Again thanks people. . .