This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Serial1 on MSP432P401R using energia

Other Parts Discussed in Thread: ENERGIA

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);
  }



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.

**Attention** This is a public forum