- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
See the attached project.
What I am trying to do is read data, then send it to a 0-5V DAC chip (MCP4725). I have no problem reading the data, but when it goes from my data buffer to be written to the I2C port, something bad happens, because the DAC does not respond correctly. See the picture I captured in the zip file. The value of the data is, correctly, 0xA1, or 161. If I manually retype '0xA1' in the bracket instead of putting the variable, it works like it is supposed to. Do I need to 'cast' the hex as an integer somehow, or inform the compiler what type of data it is?
I know, this is probably extremely basic C programming stuff, but please bear with me.
Thank you,
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Another question is - how do I 'poll' the pointer to find out where it is in the buffer?
Just make the pointer global, volatile, and poll its value ? Of course
if thats being updated in an ISR your test would be >= some address ?
Don't test for equality as you may miss one or more address's
Regards, Dana,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
bring an old thread back to life! I'm just wondering, if I was to pass a 16 bit value from an ADC, would I simply split the data and pass data[0] = 0x40, data[1] = first 8 bits, data[3] = last 8 bits?
D
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Because your two devices (PSoC and I2C-slave) might have different endianess you have to consider the order to send your bytes.
When the endianess is the same, a simple type cast from (int16*) to (char*) of the data argument would be ok. If not you will have to separate high and low byte by masking and shifting as
highbyte is (char)(((int16) Data >> 😎 & 0xff00)
and lowbyte is (char)((int16)Data & 0x00ff)
Bob