- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all!
I have a CY8CKIT-059 , it's great, done lots of little things so far. Tonight I decided i'd try and write some values to a 12-bit DAC.
I looked at a few example projects etc and can not seem to get another to come out that makes sense above about 800Hz, it's all blocky and modulated.
I'm pretty sure the sample rate and the conversion rate are more than adequate. Any thing i'm missing? I might also be doing the bit shifting wrong,,,,
Code looks like this.
#include <project.h>
#define SLAVE_ADDRESS 0x62
#define WR_BUFFER_SIZE (2u)
int main()
{
uint8 sample_segment[WR_BUFFER_SIZE];
uint16 sample_full;
Opamp_1_Start();
I2C_1_Start();
ADC_1_Start();
CyGlobalIntEnable;
for(;;)
{
ADC_1_StartConvert();
/* Wait until the ADC conversion is complete */
ADC_1_IsEndConversion(ADC_1_WAIT_FOR_RESULT);
/* Since the ADC conversion is complete, stop the conversion */
ADC_1_StopConvert();
sample_full = ADC_1_GetResult16();
sample_segment[0] = sample_full >> 8u & 0x00FFu;
sample_segment[1] = sample_full & 0x00FFu;
I2C_1_MasterWriteBuf(SLAVE_ADDRESS, (uint8 *)sample_segment,WR_BUFFER_SIZE, I2C_1_MODE_COMPLETE_XFER);
}
}
- Labels:
-
ispn:39618:1:0
-
l1:314:1:0
-
PSoC5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum!
The function I2C_1_MasterWriteBuf() returns a status which is zero when success. Otherwise there will be returned a value indicating the cause. See in i2c_1.h - file for the #defined constants.
There is no need to ADC_StartConvert() and StopConvert() within the infinite loop, it would be faster just waiting for a conversion ready, everything is handled within the API.
Next time do not post only a code snippet, but your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So, i've added some error checking and it works as expected. I think the problem is the value i'm writing to the I2C DAC. With the I2C_1_MasterWriteBuf() command do I have to include start bits etc? The DAC is a MCP4725, a DAC which has been used in a pervious discussion but i'm confused by their resolution to the problem.
D
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yes, I'm just confused by the masterbuffer function but think i'm starting to understand it with the help of the other threads source code.