Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 11 months ago.
MCP4725 .write function not working with mbed NXP LPC1768
Hello, We are currently using a mbed NXP LCP1768 to output a digital signal over the I2C to the MCP4725 to create an analog waveform. Our problem is with the .write function when we test the program we included a line that outputted write failed to puTTy when the value of wave.write was non-zero. We have the libraries for the MCP4725 in the same folder as our main.cpp and have looked up numerous code examples that use the same syntax we are using. Please let me know if you have any idea what the problem might be with the code for the MCP4725.
Thanks, -Dan White Dixie Engineering Project Manager
PARTIAL CODE FOR MCP4725
MCP4725 wave(p9, p10, MCP4725::Fast400kHz, 0); if(SelectWave.data[0] == 50) Key = 2 { A=wave.write(MCP4725::Normal, (0xFFF*3.3), false); if (A==0) pc.printf("Successful Write"); if (A!=0) pc.printf("Failed Write");
wave.write(MCP4725::Normal, (0xFFF*3.3), false); wait(0.5); wave.write(MCP4725::Normal, (0x000), false); wait(0.5);
}
FULL CODE STARTS BELOW
- include "mbed.h"
- include "mcp4725.h"
- include "math.h"
- include "CAN.h" using namespace std;
Serial pc(USBTX, USBRX); SPI spi(p11, p12, p13); SPI Bus (mosi, miso, sclk) DigitalOut cs(p14); Clip Select Pin for DigiPot CAN can2(p30, p29); mbed pins connected to CAN
class instantiation MCP4725 wave(p9, p10, MCP4725::Fast400kHz, 0);
const double PI = 3.14159;
int main() { CANMessage SelectWave;
bool Start = false; pc.printf("putty initialized"); while (1) { can2.read(SelectWave); if (SelectWave.id == 3) { if (SelectWave.data[0] == 8) { Start DAC Output pc.printf("start message received"); break; } } }
while (1) { can2.read(SelectWave); 1-Hz Square Wave if(SelectWave.data[0] == 50) Key = 2 {
wave.write(MCP4725::Normal, (0xFFF*3.3), false); wait(0.5); wave.write(MCP4725::Normal, (0x000), false); wait(0.5);
}
10-Hz if(SelectWave.data[0] == 51) Key = 3 { wave.write(MCP4725::Normal, (0xFFF), false); wait(0.05); wave.write(MCP4725::Normal, (0x000), false); wait(0.05); } 1-Hz Sine Wave if(SelectWave.data[0] == 52) Key = 4 { for(int i=0; i<=1000; i++) { wave.write(MCP4725::Normal, (0xFFF*(0.5*sin(2*PI*i/1000)+0.5)), false); wait_us(860); } }
10-Hz Sine Wave if(SelectWave.data[0] == 53) Key = 5 {
for(int i = 0; i <= 1000; i++) { wave.write(MCP4725::Normal, (0xFFF*(0.5*sin(2*PI*i/1000)+0.5)), false); wait_us(860); } }
Stop DAC Output if(SelectWave.data[0] == 35) Key = # { wave.write(MCP4725::Normal, (0x000), false); } }
}
Please repost your code with the proper markers of:
posted by Sanjiv Bhatia 07 Dec 2016<<code>> ; before the start of your code <</code>>
; at the end of your code