I have a distance of 6cm between mbed and the energy measurement chip. It's soldered in a PCB. I'm making right now a new design to test with a distance of only 1cm.
The accepted values for the SPI communication at ADE7758 need to be between 5MHZ and 15MHZ, as you can see at page 5 of the ADE7758 datasheet available at http://www.analog.com/static/imported-files/data_sheets/ADE7758.pdf .
I'm testing in this PCB the code below and I only start to get the right values after 50 reads. If I updated the mbed file to read a new register, it gives the right value but if I turn the mbed off and 15 minutes start the mbed again, it gives me 0xFF. After 50 reads or more it gives again the right value.
- include "mbed.h"
SPI spi(p5, p6, p7); mosi, miso, sclk
DigitalOut cs(p8);
uint8_t packet[9];
Serial pc(USBTX, USBRX);
/* Configuração MBED*/
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
********
register name address length
********
read only register
- define REACTIVE_A 0x01 16 Watt-Hour Accumulation Register for Phase A
- define REACTIVE_B 0x02 16 Watt-Hour Accumulation Register for Phase B
- define REACTIVE_C 0x03 16 Watt-Hour Accumulation Register for Phase C
- define AVARHR 0x04 16 Var-Hour accumulation register for phase A
- define BVARHR 0x05 16 Var-Hour accumulation register for phase b
- define CVARHR 0x06 16 Var-Hour accumulation register for phase c
Timer timeout;
bool timed_out;
int main() {
uint8_t status_byte = 0x00;
timeout.start(); start the timeout timer
while (1) {
try the 4 available modes to see if it will work
for(int mode = 0; mode < 3; mode++) {
spi.format(8, mode);
spi.frequency(10000000); 10MHz on sck
cs = 0;
led1 = 1;
printf("Testing Command in SPI Mode %d\r\n", mode);
spi.write(0x17); send command byte
wait(0.01);
timeout.reset(); reset the timeout to wait for reply for 2 seconds
timed_out = false;
wait for the status byte
while (status_byte == 0x00) {
status_byte = spi.write(0x00);
wait(0.01);
waited too long timeout
if (timeout.read_ms() > 1000) {
timed_out = true;
break;
}
}
if (!timed_out) {
packet[0] = status_byte;
have the status (should check it really)
get the rest of the packet
for (int i=1; i<5; i++) {
packet[i] = spi.write(0x00);
}
output the packet
for (int i=0; i<5; i++) {
printf("%02X ", packet[i]); output the bytes in hex format on one line
}
printf("\r\n");
} else {
printf("Command timeout..\r\n");
}
cs = 1; must raise cs between commands but after the reply
led1 = 0;
wait(0.5);
}
}
}
Regards
Hi,
Currently I have my mbed connected to an energy measurement chip ADE7758 that uses SPI to communicate the energy data, but the problem is that this chip uses a clock oscillator of 10MHz and mbed is using only 4MHz. I tried to change the spi.frequency on the mbed to 10MHz but the energy chip doesn't receive the full data as I could verify on the oscilloscope.
How I can change the mbed internal oscillator do start using 10MHz on the SPI communication?
Here is the code that I'm using: