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.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
Hello,
I'm starting a new project but don't have to much experience in C, and my goal is to measure the Volts that are available in the port 20 (DigitalIn). Currently I'm only sending the integer part, but I want to know how I can send the complete measure (e.g. I read 2.55V in MBED1 and I want to send via CAN BUS to receive in the MBED2 the 2.55V).
For this project I'm using the following material:
In MBED1 I'm using the following code:
#include "mbed.h" #include "CAN.h" AnalogIn ain(p19); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); CAN can1(p30, p29); Serial pc(USBTX,USBRX); //tx. rx int main() { char value = 0; float measure = 0; pc.baud(9600); can1.frequency(125000); /*********Program Starts Here***************/ while(1) { measure = (0.707631 * ain) / 0.211966; value = (int) measure; if(can1.write(CANMessage(0x42, &value, 2))) { led1 = 1; pc.printf("> %u volts ", value); pc.printf("-- %f volts \n", measure); } wait(2.0); led1 = 0; measure = 0; } }And in MBED2 I'm using this code to print out the values:
#include "mbed.h" #include "CAN.h" DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); CAN can2(p30, p29); Serial pc(USBTX,USBRX); //tx. rx int main() { CANMessage msg; float measure = 0; pc.baud(9600); can2.frequency(125000); /*********Program Starts Here***************/ while(1) { wait(0.5); if(can2.read(msg)) { led2=1; pc.printf("Received value: %02X volts",msg.data[0]); measure = (int) msg.data[0]; pc.printf(" --- Value in Volts >> %4.2f V\n", measure); } led2 = 0; wait(0.2); led4 = !led4; measure = 0; } }Regards