8 years, 8 months ago.

How to code in C++ to read data of a register using spi bus

  1. include "mbed.h"

SPI spi(p11, p12, p13); mosi, miso, sclk DigitalOut cs(p14); Serial pc(USBTX,USBRX);

int main() { Chip must be deselected cs = 1;

Setup the spi for 8 bit data, high steady state clock, second edge capture, with a 1MHz clock rate spi.format(8,3); spi.frequency(100000);

Select the device by seting chip select low cs = 0;

spi.write(0x01);read command spi.write(0x15<<2);address Vrms ,register address needs to be shifted twice tothe left int VA_RMS=spi.write(0x00);dummy , sending three dummy bytes , enough to clock out the 24 bit data spi.write(0x00); dummy spi.write(0x00); dummy

Deselect the device cs = 1;

}

my question is how do i retrieve the 24 bit data in Vrms register , and use it for any meaningful calculation reference document MAX78615+PPM . i see the data on a logic analyser but dont know how to output it on tera term

Be the first to answer this question.