Go Down

Topic: Adding more Serial Interfaces to SAMD microcontrollers (Read 759 times) previous topic - next topic

ageissler

Hi, works the description for the MKR1000 also for the MKR WAN 1300? Unfortunately the MKR 1300 doesn't have Software Serial, for me this would be enough... therefore a second UART is necessary... THX in advance for a short information  :)     

mjunior-fitec

Hello.
I really would like to help you. I am using 3 serial interfaces currently on my MKRWAN1300.
Unfortunately I just can't understand what is your question  :o

Can you please tell me what is your problem? What, exactly, are you trying to do and having no success?

Regards,
Marcio Jr.

volatile

Hi all, I am having exit status 1 while trying to increase the number of serial ports on my MKR1300. Here is the code. Can anyone assist? Thank you.

#include <Arduino.h>
#include <wiring_private.h>

#define PIN_SERIAL2_RX    (1ul)     //Pin description number for PIO_SERCOM on D1
#define PIN_SERIAL2_TX    (0ul)     //Pin description number for PIO_SERCOM on D1
#define PAD_SERIAL2_TX    (UART_TX_PAD_0)  //SERCOM pad 0 TX
#define PAD_SERIAL2_RX    (SERCOM_RX_PAD_1)//SERCOM pad 1 RX
//Instantiate the Serial2 class
Uart Serial2(&sercom3, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX);

const byte rxPin = 13;
const byte txPin = 14;


int DEACTIVATE_PWM = 0;

//set up a new serial port
//SoftwareSerial mySerial (rxPin, txPin);

void setup() {
  //// put your setup code here, to run once:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);

  ////set the data rate for the software serial port
 
  Serial1.begin(19200);
  Serial.begin(19200);
  //DeactivatePWM();

  //Adding additional serial port
  Serial2.begin(38400);     //might be an assumption
  pinPeripheral(0, PIO_SERCOM); //Assign RX function to pin 0
  pinPeripheral(1, PIO_SERCOM); //Assign TX function to pin 1
}

void loop() {
  //Command to deactivate PWM
  if (DEACTIVATE_PWM < 2){
    DeactivatePWM();
    DEACTIVATE_PWM = 1 + DEACTIVATE_PWM;
  }

  //Additional serial port interface
  if(Serial2.available()){
    byte byteRead = Serial2.read();    //Read the most recent byte
    Serial2.write(byteRead);          // Echo the byte back out on the serial port
  }
  //Command to read distance
  Start_reading_distance();

}

////////////////////////////////////////////////////////////////////
// Attach the interrupt handler to the SERCOM; for additional serial port
void SERCOM3_Handler()
{
  Serial2.IrqHandler();
}
////////////////////////////////////////////////////////////////////
void Start_reading_distance(){
   
  byte Check_byte;
  byte Data_byte;
  //Request measurement from sensor
  byte inputBuffer[] = {0xAF, 0xFE, 0xFE, 0x61};
  Serial1.write(inputBuffer, 4);
  delay(100);
 
  Serial.println("Requesting data from sensor:");
  while (Serial1.available() >0){
   
    if(Serial1.available() == 2){
      Data_byte = Serial1.read();
      Serial.println(Data_byte);
    }
    if(Serial1.available() == 1){
      Check_byte = Serial1.read();
      Serial.println(Check_byte);
    }
    //Clear serial buffer if its not check or data byte
    Serial1.read();
  }
}
////////////////////////////////////////////////////////////////////
void DeactivatePWM() {
  //Deactivate PMW first

  byte deactivateBuffer[] = {0xA0, 0x00, 0xA7, 0x0A, 0x01};
  Serial.println("Send deactivation code");
  Serial1.write(deactivateBuffer, 5);
 
  //wait for sensor to master response
  while(Serial1.read() != 81){
  }

  //delay(1000);
  Serial.println("Confirmation CHECK byte RECEIVED");
  //Full command to deactivate PWM
  byte deactivatePWM[] = {0xA7, 0x0A, 0x01, 0x51};
  Serial1.write(deactivatePWM, 4);
  Serial.println("Clear full command buffer");
  //delay(500);
  //while(Serial1.available() > 0){
    //Serial.println(Serial1.read());
    //delay(1000);
  //}
}

volatile

@ mjunior-fitec

I am trying to add more serial ports using the code attached. But i keep getting exit status 1 upon compiling of the code.

I have found out the problem. I do not have wiring_private.h

Can you post your code cause now, my MKR1300 does not seem to be working after adding the serial port.

Go Up