12 years, 1 month ago.

Send commands to mbed

Hello, mbed pros! I am new to mbed. I connect mbed to pc and want to transmit 7 bytes hexdecimal command to mbed and want to see feedback on pc. The seven bytes hex command is like this, FF 01 00 04 3F 00 44. I have no idea how to write the code. I will be grateful if anyone could give advice.

Best regards

2 Answers

12 years, 1 month ago.

As I said, just have a look at scanf, you probably can do it nicer with a loop, but it works:

#include "mbed.h"

int main() {
    int buffer[7];
    scanf("%2X %2X %2X %2X %2X %2X %2X", &buffer[0], &buffer[1], &buffer[2], &buffer[3], &buffer[4], &buffer[5], &buffer[6]);
    printf("received %d - %d - %d - %d - %d - %d - %d\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6]);
 
}

Accepted Answer

Thanks a lot. i changed a little bit to display in hex.

posted by Neil Powell 19 Nov 2012

I have finished the first step, using scanf and printf to input and show the hex commands on PC. My second step is to transmit command from pc through mbed to camera. Shall I combine the first code with "Pass through characters in both directions between the PC and Serial Port", which is shown in the serial communication with a pc?

posted by Neil Powell 20 Nov 2012

That works fine yes to work as serial bridge.

posted by Erik - 20 Nov 2012
12 years, 1 month ago.

I dont know which way you know want to send stuff exactly, but have a look at the printf and scanf commands, especially while using %X

I am doing a protocol converter. My first step is that the microprocessor can read the command. The command is 7 bytes in hexdecimal(like FF,01,00,04,3F,00,44). So I want to write the C-program that can receive the command and show it on the PC. Do you have any advice? Thanks!

posted by Neil Powell 18 Nov 2012