Reading TI-ADS1115 in Tachyon
artkennedy
Posts: 174
When I use this code to read a conversion from a TI-ADS1115 ADC the LSB is all zeros. Anything wrong here? Using Tachyon Neon with EXTEND5v4 on Prop 1.
- $90 := @ADC \ ( --- ) define CONSTANT for adc 8-bit I2C address - this is the I2C address for the ADC board
-
ADC16@ ( reg -- dat16 ) \ read contents from a TI-1115 register
W \ combine bytes into a word
I2C> \ that's all for now
;
Comments
OK, I was trying to use markdown and screwed up the code block. Here is the code unformatted:
ADC16@ ( reg -- dat16 ) \ read contents from a TI-1115 register
W \ combine bytes into a word
I2C> \ that's all for now
;
Well it is still messed up. Trying again:
ADC16@ ( reg -- dat16 ) \ read contents from a TI-1115 register
W \ combine bytes into a word
I2C> \ that's all for now
;
That was without any attempt to formatting. It leaves out most of the code. Don't understand.
I'll try it this way:
Could also use a reminder of how to post code in the forum.
Alright I took the markdown tutorial ( after I found it ) ...
Normally the last data byte read is nak'd but the timing diagram shows an ack. However it has a note (3) which says "master can leave SDA high to terminate a two=byte read operation" which probably needs to be done anyway if you are stopping there, and the timing diagram should have shown that. However it also implies that you can leave the device selected and just read more data bytes for more samples, although i would probably test that out.
Here's my simplified version that issues a nak on the last byte. Whether I use SWAP B>W or 8<< + in the right place doesn't make a whole lot of difference.
The register pointer probably would be reset to 0 at power-up and so there is no need to select the data register each time. My suggestion would be if you are not writing to any other registers then don't worry about it. However if you do want to write to a register then make sure you reset the register pointer on exit.
BTW
To format code just use the backtick (above the tilde near your esc key) or select code from the format icon to the right of the unordered list icon.
To format Inline code manually just backtick mycode backtick and for multiline it is three backticks on a line before and three after
backtick backtick backtick
my code
more code
and more code
backtick backtick backtick
After the first three backticks you can also specify an optional language for syntax highlighting if it is supported (no spaces)
backtick backtick backtick python
my Python code
more code
and more code
backtick backtick backtick