MSP432 0 Posted November 11, 2016 Share Posted November 11, 2016 Hi, I am trying to make a UART connection with a device from serial1 in MSP432. It isn't working as i cannot see anything printing on my serial monitor (I am trying to print the data stored in global variables using serial/USB). Wherein the same code works fine on MSP430 or TM4C1294 devices. I have double checked my wiring connections.. P3.2, P3.3 for RX, TX. Can anyone here help me resolve this issue or point out where im going wrong.. Please find the code below //----------------------------------------------------------------------------- // Microchip MCP39F501 Power Monitor TI Interface Sample Code #define ACK 0x06 #define NACK 0x15 #define CSFAIL 0x51 int OK1_Count = 0; // Success/No Success Counter for Reg Read 0x0002 int NOK1_Count = 0; byte Xmit_Dly = 2; // Transmit Delay between bytes, in msec byte Header; // Received ACK/NACK/CSFAIL byte byte Byte_Count; // Reveived Byte count byte CurrentRMS_LL; // 0x0004 CurrentRMS byte CurrentRMS_L; // 0x0005 CurrentRMS byte CurrentRMS_H; // 0x0006 CurrentRMS byte CurrentRMS_HH; // 0x0007 CurrentRMS byte VoltageRMS_L; // 0x0008 Voltage RMS byte VoltageRMS_H; // 0x0009 Voltage RMS byte ActivePower_LL; // 0x000A ActivePower byte ActivePower_L; // 0x000B ActivePower byte ActivePower_H; // 0x000C ActivePower byte ActivePower_HH; // 0x000D ActivePower byte ReactivePower_LL; // 0x000E ReactivePower byte ReactivePower_L; // 0x000F ReactivePower byte ReactivePower_H; // 0x0010 ReactivePower byte ReactivePower_HH; // 0x0011 ReactivePower byte ApparentPower_LL; // 0x0012 ApparentPower byte ApparentPower_L; // 0x0013 ApparentPower byte ApparentPower_H; // 0x0014 ApparentPower byte ApparentPower_HH; // 0x0015 ApparentPower byte PowerFactor_L; // 0x0016 PowerFactor byte PowerFactor_H; // 0x0017 PowerFactor byte Freq_L; // 0x0016 Frequency byte Freq_H; // 0x0017 Frequency byte CheckSum; byte CalculatedCS; float CurrentRMS; // Current RMS float VoltageRMS; // Voltage RMS float ActivePower; // Active Power float ReactivePower; // Reactive Power float ApparentPower; // Apparent Power float PowerFactor; // Power Factor float Freq; // Frequency void setup() { Serial.begin(9600); Serial.println("Entering Loop "); } void loop() { if (RegRead0x0004()) { OK1_Count++; } else { NOK1_Count++; } Serial.println("------------------------------------------"); Serial.print("MCP39F501 DEMO BOARD : "); Serial.println("------------------------------------------"); Serial.println("OUTPUTS"); Serial.print("RMS Current : "); Serial.print(CurrentRMS*0.0001,4); Serial.println(" A"); Serial.print("RMS Voltage : "); Serial.print(VoltageRMS*0.1,1); Serial.println(" V"); Serial.println("DATA COMMUNICATION"); Serial.print("1st frame counts: OK="); Serial.print(OK1_Count,DEC); Serial.print(", Not OK="); Serial.println(NOK1_Count,DEC); delay(1000); } bool RegRead0x0004(void) { Serial1.begin(4800); WriteByte(0xA5); WriteByte(0x08); WriteByte(0x41); WriteByte((byte)0x00); WriteByte(0x04); WriteByte(0x4E); WriteByte(0x16); WriteByteND(0x56); ClearBuffer(); // Parse the data returned from the meter if (Serial1.available()) { Header = Serial1.read(); Byte_Count = Serial1.read(); CurrentRMS_LL = Serial1.read(); CurrentRMS_L = Serial1.read(); CurrentRMS_H = Serial1.read(); CurrentRMS_HH = Serial1.read(); VoltageRMS_L = Serial1.read(); VoltageRMS_H = Serial1.read(); ActivePower_LL = Serial1.read(); ActivePower_L = Serial1.read(); ActivePower_H = Serial1.read(); ActivePower_HH = Serial1.read(); delay(50); ReactivePower_LL = Serial1.read(); ReactivePower_L = Serial1.read(); ReactivePower_H = Serial1.read(); ReactivePower_HH = Serial1.read(); ApparentPower_LL = Serial1.read(); ApparentPower_L = Serial1.read(); ApparentPower_H = Serial1.read(); ApparentPower_HH = Serial1.read(); PowerFactor_L = Serial1.read(); PowerFactor_H = Serial1.read(); Freq_L = Serial1.read(); Freq_H = Serial1.read(); CheckSum = Serial1.read(); } Serial1.end(); Serial.print("Cehcksum Received: "); Serial.println(CheckSum,HEX); // Calculate the expected CheckSum CalculatedCS = (byte)((int)( Header + Byte_Count + CurrentRMS_LL + CurrentRMS_L + CurrentRMS_H + CurrentRMS_HH + VoltageRMS_L + VoltageRMS_H + ActivePower_LL + ActivePower_L + ActivePower_H + ActivePower_HH + ReactivePower_LL + ReactivePower_L + ReactivePower_H + ReactivePower_HH + ApparentPower_LL + ApparentPower_L + ApparentPower_H + ApparentPower_HH + PowerFactor_L + PowerFactor_H + Freq_L + Freq_H + 0)%256); Serial.print("Checksum Calculated: "); Serial.println(CalculatedCS,HEX); // Check for ACK, correct byte count and CheckSum matches expected checksum if ((Header == 0x06) ){//&& (Byte_Count == 0xD) && (CheckSum == CalculatedCS)) { Serial.println("IM HERE"); CurrentRMS = ((unsigned long)(CurrentRMS_HH << 24) + (unsigned long)(CurrentRMS_H << 16) + (unsigned long)(CurrentRMS_L << 8) + (unsigned long)(CurrentRMS_LL)); VoltageRMS = ((unsigned int)(VoltageRMS_H << 8) + (unsigned int)(VoltageRMS_L)) ; return true; } else return false; } void WriteByte(byte _wbyte) { Serial1.flush(); Serial1.write(_wbyte); delay(Xmit_Dly); } void WriteByteND(byte _wbyte) { Serial1.flush(); Serial1.write(_wbyte); //delay(Xmit_Dly); } void ClearBuffer(void) { Serial1.flush(); while(Serial1.available()) char _f = Serial1.read(); delay(30); } Quote Link to post Share on other sites
Fmilburn 446 Posted November 14, 2016 Share Posted November 14, 2016 Hi @@MSP432, Can you explain what you mean by It isn't working as i cannot see anything printing on my serial monitor (I am trying to print the data stored in global variables using serial/USB). I pasted the code in a MSP432 and Energia V18 and it is printing to the serial monitor. Of course all the data is 0 because I don't have a sensor hooked up. I attached my logic analyzer to P3_3 and I see serial1 output. Quote Link to post Share on other sites
MSP432 0 Posted November 14, 2016 Author Share Posted November 14, 2016 So when i run the code. if (Serial1.available()) this statement always FAIL. Program never enters into that if loop, it is just skipping that. As a result the Serial1.end(); after the IF loop is halting the program there and the loop breaks. As a result i cannot see anything print on my serial monitor. But the same code works well with MSP430. What would the issue be? Should i change some jumper settings on my MSP432 for the Serial1 to work. I tried on multiple MSP432 boards both red and black nothing worked. Quote Link to post Share on other sites
Fmilburn 446 Posted November 14, 2016 Share Posted November 14, 2016 @@MSP432 Try hooking a jumper between P3_2 and P3_3, then run this sketch... void setup() { Serial.begin(115200); Serial1.begin(115200); Serial.println("Starting..."); } void loop() { Serial1.write('A'); if (Serial1.available()) { int inByte = Serial1.read(); Serial.write(inByte); } delay(1000); } If it runs, then at least your LaunchPad is sending and receiving Serial1. It worked for me with Energia V18 and a black MSP432. Past that it is just guessing for me since you say it works on other LaunchPads and I don't have the sensor. Try getting hold of an oscilloscope or logic analyzer so you can see the signals. Edit: Posting a picture of your setup may help someone diagnose the problem Quote Link to post Share on other sites
MSP432 0 Posted November 14, 2016 Author Share Posted November 14, 2016 Here is how the setup is.. And your code was working fine. I am able to print char A on serial monitor. MSP432 + MCP39F501 Quote Link to post Share on other sites
Fmilburn 446 Posted November 15, 2016 Share Posted November 15, 2016 The datasheet for the MCP39F501 says the default baud rate is 4.8 kbps. Are you sure the baud rate is right? It seems that the LP is sending data but the MCP39F501 is not responding. EDIT: In your photo it is not evident that they share ground Quote Link to post Share on other sites
MSP432 0 Posted November 15, 2016 Author Share Posted November 15, 2016 Ground!! Thats a big question even i had. But luckly it was working (I dnt knw how its referencing the signal though) as expected on MSP430 and TM4C1294. When i look at the higher version MCP39F511, this piece has a ground connection pin available from MCP to MSP. But the MCP board i am using doesn't have any ground pin to connect to. And yes my baud rate is 4.8kbps (code snippet attached) bool RegRead0x0004(void) { Serial1.begin(4800); Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.