We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am reading data from a sensor via I2C using an MSP432 Launchpad. I am trying to send this data to Processing via UART, but the data is almost always corrupted. I have verified using a logic analyzer that I am reading and sending the correct data from the MSP432. The following while loop is my code from CCS.
while (1)
{
if (P6IN & BIT7)
{
Setup_Register(0x49, 0x08, 0x20);
X1 = Read_Data_Register(0x00);
X2 = Read_Data_Register(0x01);
Y1 = Read_Data_Register(0x02);
Y2 = Read_Data_Register(0x03);
MAP_UART_transmitData(EUSCI_A0_BASE, 0x0a);
UART_Transmit(X1);
UART_Transmit(X2);
UART_Transmit(Y1);
UART_Transmit(Y2);
}}
The follwing is my code from Processing.
import processing.serial.*;
Serial myPort;
int X1, X2, Y1, Y2;
float h, v;
void setup() {
printArray(Serial.list());
myPort = new Serial(this, Serial.list()[3], 19200);
}
void draw() {
byte[] inBuffer = new byte[8];
while(myPort.available() > 0) {
myPort.readBytesUntil(0x0a);
myPort.readBytes(inBuffer);
X1 = (inBuffer[1] << 8) + inBuffer[0];
X2 = (inBuffer[3] << 8) + inBuffer[2];
Y1 = (inBuffer[5] << 8) + inBuffer[4];
Y2 = (inBuffer[7] << 8) + inBuffer[6];
println("X1: " + hex(X1) + "\tX2: " + hex(X2) + "\tY1: " + hex(Y1) + "\tY2: " + hex(Y2));
}
}
Most of the time, the data displayed on Processing is -8224. Sometimes, they are random positive and negative numbers that jump around. What could be causing this issue? Any help is appreciated!
Answers
Edit post, select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below....
Kf
Problem was with Processing. One of the data packets contained 0x0a which was throwing off the reads. Changed it to 0x00 to mark a new data packet and now it's working.