I'm new to ContikiOS and I'm having an issue when trying to send a character to my cc2650-launchpad from my Raspberry Pi using the UART interface.
I want to make my Raspberry Pi communicate by serial interface with a cc2650 launchpad. I can read serial output from the launchpad perfectly but I am unable to send something to the launchpad from the RPi through serial.
I have configured my Raspberry Pi to enable UART following this tutorial (I'm using Raspbian Jessie) and configured the launchpad running Contiki to receive serial messages according to Contiki documentation.
When testing on TeraTerm (Serial monitor for Windows) I am able to recieve the characters on the launchpad by typing on the terminal window and pressing 'CTRL + ENTER', which sends a "\n" character (ASCII = 0x0A). The launchpad works as expected.
However, when I try to automate things on my Raspberry Pi using a program written in Python, it appears the character is not received by the launchpad (or the selial line event is not triggered).
What I get is the following behavior:
Wrong behavior (on Raspberry Pi)
And this is what I expected:
Expected Behavior (on Windows Machine)
As seen on the first image above, even after sending the character 'T' many times (upper window), the launchpad dows not receive anything (bottom window) The behavior is the same when connecting the launchpad by USB (ttyACM0) and by UART pins (ttyAMA0). I don't believe the problem is with the launchpad firmware since it works well when it is interfacing with a Windows machine (image 2). So the problem must be with my Raspberry Pi configuration or my with Python code.
Does anybody know what I might be doing wrong?
Source code for reference: Raspberry Pi:
#Python code running on Raspberry Pi
import serial
import time
uart_port = serial.Serial("/dev/ttyACM0", 115200);
while True:
uart_port.write("T")
uart_port.write("\n");
print("Sent 'T'")
time.sleep(1)
CC2650 Launchpad:
...
#include "dev/serial-line.h"
...
PROCESS_THREAD(udp_server_process, ev, data)
{
char * serial_msg_recv = NULL;
PROCESS_BEGIN();
printf("Starting Server Node...\n");
cc26xx_uart_set_input(serial_line_input_byte);
SENSORS_ACTIVATE(button_sensor);
...
while(1) {
PROCESS_YIELD();
if(ev == tcpip_event) {
tcpip_handler();
}
if(ev == serial_line_event_message && data != NULL) {
printf("command received:%s\n",(char *)data);
serial_msg_recv = (char *)data;
if(serial_msg_recv[0]=='T'){
send_toggle();
printf("_A"); // send ACK
serial_msg_recv = NULL;
}
else{
printf("Invalid command received from serial interface\n");
}
}
}
PROCESS_END();
}
EDIT1: I just connected the Raspberry Pi's Tx and Rx pins directly. The Python script is sending the characters correctly. This excludes the "RPi configuration problem" hypothesis and makes me believe that, for some reason, Contiki is not triggering an event when it receives the '\n' character.
EDIT2: I created a custom uart callback to be executed at every character received (so I wouldn't have issues with process events or \n and \r characters). The behavior is OK on Windows but still no luck on the Raspberry Pi. The problem persists even when lowering the bauldrate from 115200 to 9600.
Here is the custom UART callback:
static int uart_rx_callback(unsigned char c) {
printf("\nReceived %c",c);
return 0;
}
And the new configuration:
cc26xx_uart_set_input(uart_rx_callback);
EDIT3: I tested the Python code on an Ubuntu Virtual Machine with the launchpad connected through USB. The launchpad is able to receive all characters I send to it. It appears the problem is with the Raspberry Pi.