alexlennick (Customer) asked a question.

Setting up a third serial device on a P1AM-200.

Hello,

 

I have 2 serial devices working using a P1AM-GPIO shield on pins 0, 1 and 13, 14. I need to setup a third, and am using pins 2, 3. Given the code below, I am getting the 'testn' text to print on the serial monitor and the loop is running as it should. However, I am not seeing the received data that should be printing as well. Any help is greatly appreciated!

 

#include <Arduino.h>

#include "wiring_private.h"

#include <P1AM.h>

 

#define SERIAL_3_RX_PIN (3)

#define SERIAL_3_TX_PIN (2)

#define SERCOM_RX_PAD_VAL SERCOM_RX_PAD_3

#define SERCOM_TX_PAD_VAL UART_TX_PAD_2

 

Uart SerialTest(&sercom6, SERIAL_3_RX_PIN, SERIAL_3_TX_PIN, SERCOM_RX_PAD_VAL, SERCOM_TX_PAD_VAL);

 

void SERCOM6_0_Handler()

{

  SerialTest.IrqHandler();

}

void SERCOM6_1_Handler()

{

  SerialTest.IrqHandler();

}

void SERCOM6_2_Handler()

{

  SerialTest.IrqHandler();

}

void SERCOM6_3_Handler()

{

  SerialTest.IrqHandler();

}

 

void setup() {

  Serial.begin(115200);

  delay(50);

  while (!Serial);

 

  Serial.println("P1AM-200 Serial Test Starting...");

 

  Serial.print("pinPeripheral D2 (RX) result: ");

  Serial.println(pinPeripheral(SERIAL_3_RX_PIN, PIO_SERCOM));

 

  Serial.print("pinPeripheral D3 (TX) result: ");

  Serial.println(pinPeripheral(SERIAL_3_TX_PIN, PIO_SERCOM));

 

  Serial.println("test1");

  // Initialize the custom HardwareSerial port

  SerialTest.begin(38400, SERIAL_8N1);

  Serial.println("test2");

 

  Serial.println("SerialTest (38400 baud) ready on D2 (RX) and D3 (TX).");

}

 

void loop() {

  // ... (rest of loop remains the same)

  Serial.println("test3");

  if (SerialTest.available()) {

    Serial.println("test4");

    receive_read_live_data_simple();

    Serial.println("test5");

  }

  Serial.println("test6");

  send_read_live_data_simple();

  Serial.println("test7");

  delay(1000);

  Serial.println("test8");

}

 

void send_read_live_data_simple(){

  Serial.println("Sending 7 bytes on SerialTest...");

  byte buf[] = {0x10, 0x13, 0x2C, 0x10, 0x1F, 0x19, 0xB4};

  SerialTest.write(buf, sizeof(buf));

}

 

void receive_read_live_data_simple(){

  Serial.print("Rx Data: ");

  while (SerialTest.available())

  {

    Serial.print(SerialTest.read(), HEX);

    Serial.print("|");

  }

  Serial.println();

}