Serial2 and Serial3 for adafruit Grand central M4

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
4MInnovations
 
Posts: 13
Joined: Wed Jul 29, 2015 8:17 am

Serial2 and Serial3 for adafruit Grand central M4

Post by 4MInnovations »

Hi all,
I'm trying to run a stepper motor with the accelStepper library in arduino ide, a TMC2209 drive and an Adafruit Grand central M4 (samd51).
For make this work, I need a Serial2 or Serial3, but I try what I find on the internet, but still NOT WORKING.

Did you have a example of arduino coding with a Serial2 or Serial3 working?

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: Serial2 and Serial3 for adafruit Grand central M4

Post by dastels »

Serial2 and Serial3 instances aren't defined in the Arduino board support for the Grand Central. However, the support for them appears to be there. I'm playing around with it to see if I can get them working.

The files in question are (on my machine):

Code: Select all

~/.arduino15/packages/adafruit/hardware/samd/1.7.11/variants/grand_central_m4/variant.h
~/.arduino15/packages/adafruit/hardware/samd/1.7.11/variants/grand_central_m4/variant.cpp
Dave

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: Serial2 and Serial3 for adafruit Grand central M4

Post by dastels »

I got them working. I have no idea what impact enabling them will have on other SERCOM usage.

First make sure your board support is up to date.

In variant.h, near the end after the line extern Uart Serial1;

Code: Select all

extern Uart Serial2;
extern Uart Serial3;
In variant.cpp, at the very end:

Code: Select all

Uart Serial2( &SERCOM_SERIAL2, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX ) ;

void SERCOM4_0_Handler()
{
  Serial2.IrqHandler();
}
void SERCOM4_1_Handler()
{
  Serial2.IrqHandler();
}
void SERCOM4_2_Handler()
{
  Serial2.IrqHandler();
}
void SERCOM4_3_Handler()
{
  Serial2.IrqHandler();
}


Uart Serial3( &SERCOM_SERIAL3, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX ) ;

void SERCOM1_0_Handler()
{
  Serial3.IrqHandler();
}
void SERCOM1_1_Handler()
{
  Serial3.IrqHandler();
}
void SERCOM1_2_Handler()
{
  Serial3.IrqHandler();
}
void SERCOM1_3_Handler()
{
  Serial3.IrqHandler();
}
Serial2 is on pins 19 (Rx) and 18 (Tx).
Serial3 is on pins 17 (Rx) and 16 (Tx).

I tested both using a USB/serial converter (a CP2104 Friend in my case).

Dave

User avatar
4MInnovations
 
Posts: 13
Joined: Wed Jul 29, 2015 8:17 am

Re: Serial2 and Serial3 for adafruit Grand central M4

Post by 4MInnovations »

Thank you,
I tried your modification and It's seam to work for me. :)

User avatar
4MInnovations
 
Posts: 13
Joined: Wed Jul 29, 2015 8:17 am

Re: Serial2 and Serial3 for adafruit Grand central M4

Post by 4MInnovations »

Hi, I try your modifications and it seem to work, but I have a problem.
I try to use my grand central M4 to control 2 drives TMC2209 in UART (1-wire) and an 2 pins address (MS1 and MS2).

All the communication work with the default address 0, but I can't communicate with the 3 others address.

I try the exactly same setup and software with a arduino Mega, and all it's working.

The TMC2209 is 3.3V or 5V ready for the control and the uart.
I try many baud rate.
I try a 470 ohms resistors instead of the 1 kohms for passing the uart-1 wire to two wires.

Do you have any idea?

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: Serial2 and Serial3 for adafruit Grand central M4

Post by dastels »

Hard to say, as the AtMega MCU of the Arduino Mega and the SAMD51 of the GrandCentral are completely different.

Are you powering the TMC2209 with 3.3v from the GrandCentral?

Dave

User avatar
4MInnovations
 
Posts: 13
Joined: Wed Jul 29, 2015 8:17 am

Re: Serial2 and Serial3 for adafruit Grand central M4

Post by 4MInnovations »

Hi Dave,
yes, my Vmotor is 24V for the both setup.
My Vio is 5V from the Mega and 3.3V from the grand central.

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: Serial2 and Serial3 for adafruit Grand central M4

Post by dastels »

You say you're splitting one UART signal into 2? That's not something I'd do. But.. because you're running at 3.3v rather than 5v changes things. How? I'm not sure, but it probably does.

Dave

User avatar
4MInnovations
 
Posts: 13
Joined: Wed Jul 29, 2015 8:17 am

Re: Serial2 and Serial3 for adafruit Grand central M4

Post by 4MInnovations »

Hi Dave,
this is the uart:
Image

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: Serial2 and Serial3 for adafruit Grand central M4

Post by dastels »

I've never seen that done, nor can I think of why (other than the software needing the output echoed and the device not doing that. I'm curious.

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”