Serial TTL on MKR I2C pins, possible?

I am trying to connect a pre-packaged and soldered MKR 1010 WIFI to a scanning device that uses RX/TX TTL to send its data.

The I2C pins of the MKR are already wired outside it's plastic case and it would be the most convenient way to interface with the scanner.

If possible I would like to avoid adding I2C to TTL hardware and simply use the TTL lines directly on GPIO 11/12 (SDA/SCL) provided a relevant serial software exists to support it (which I couldn't find so far).

Is that possible?

Do you mean 5V logic levels?

What do you mean by RX/TX? These are terms more usually associated with a serial port UART/USART.

SCL/SDA are terms usually associated with an I2C bus, not an SPI bus.

EDIT: OP changed the discussion title to remove the reference to SPI and inserted I2C.

If your scanner is an SPI device, I think you can connect the MKR SPI output signals CS, SCK & MOSI directly to the scanning device as it will see the 3.3V logic level as a '1'. The MISO signal from the scanning device could go through a simple potential divider to give you the 3.3V logic level for the MKR .

Sorry, meant to write I2C of course (edited).

The scanner sends serial data over 2 lines (therefore RX/TX) of 5.0V TTL which I am level shifting before connecting to the Arduino.

So the question remains, and I assume it is mostly a software issue, and probably the ability to use those specific pins for serial communication.

Hmmm. What does the documentation say about serial interfaces? If those pins don't correspond to an internal UART in the MCU, you would have to use Software Serial, so look and see if there is an implementation of that library for your board.

MKR has one extra software serial called Serial1 on pins 13/14 so this would not work for me.

As for SoftwareSerial, do you know it can run on MKR and use GPIO 11/12?

It would be infinitely better to use the hardware serial, so why can't you use it exactly?

As for SoftwareSerial, do you know it can run on MKR and use GPIO 11/12?

No. I suggested already, you do the research.

SoftwareSerial is used to emulate a UART. I thought you had decided that your device used I2C?

1 Like

Please post a link, or documentation of the scanning device.

It seems like my question was not clear enough so let me try again:

The I2C pins of the MKR are already wired outside it's plastic case and it would be the most convenient way to interface with the scanner.

I posted my question long after finding SoftwareSerial do not run on MKR.

Verbal description instead of real documentation. Saw it coming, bye! I won't see any further replies from you.

There's no I2C on the scanner, just simple 5V serial RX and TX lines.

For anyone less irritated (and less superficial) here's a possible solution I just found and will research:

We are now at post #13 in your discussion and you have so far used signal names relating to UART, SPI and I2C interfaces.

It sounds reasonable that your scanner could use TTL level UART signals. Would these signals be 5V logic levels or 3.3V?

From my brief research, the MKR1000 uses a SAMD21 processor. I believe that it has 6 SERCOM modules, each of which can be configured as a UART.

This is confirmed by post #3 in the discussion you just linked to.

Assuming that you do indeed require UART TX & RX signals, then you could look to see which SERCOM is available for you to use.

The SAMD21 datasheet will tell you which SERCOM you could use. Also, the pinmux in the SAMD21 will let you route RX and TX to alternative pins.

Do you know if those wires are connected to the Arduino designated I2C pins, or another set of I2C pins on a different SERCOM?

UART is what I get from the scanner.

I2C are the pins I can easily connect to, I am not interested in using the I2C protocol, just the pins which are 11 and 12 on the MKR.

SPI is irrelevant, apology for that, I am working with SPI on daily basis and got confused with I2C (question edited to reflect that).

Scanner TTL is 5V and I am using a level shifter to make it usable on the MKR which is not 5V tolerant.

Right, this is what I picked from the Adafruit article and will try to implement.

Those are definitely connected to Arduino designated I2C pins.

Ah, now I understand. Ok, my knowledge of SERCOM setup stretches back almost 7 days as I just figured out how to add more serial ports to my Microchip Curiosity Nano SAMD21G17. Hopefully I can take what I learnt and make it work for you. So this is my workings out:

Looking at the schematic for the MKR1010 WiFi, I can see that:
SDA is on header pin 11 and routes to the SAMD21G pin PA08.
SCL is on header pin 12 and routes to the SAMD21G pin PA09.

Looking at my SAMD21G datasheet, I can see that:
PA08 can be used by SERCOM0 Pad 0 and also SERCOM2 Pad 0.
PA09 can be used by SERCOM0 Pad 1 and also SERCOM2 Pad 1.

After some reading I learnt that a SERCOM UART can receive data on any of pad 0,1,2 or 3 and that the UART can only transmit using pads 0 & 2.

Therefore you would need to use pad 0 for TX, which would appear on pin 11 on the header, and pad 1 for RX which would appear on pin 12 on the header.

Checking the variant.cpp file for the MKR1010WiFi, it defines pins 11 and 12 in the pin description array as going to actual pins 11 and 12 on the headers.

As for the actual code to do this, I think this might work for you:

#include <Arduino.h>        // required before wiring_private.h
#include "wiring_private.h" // pinPeripheral() function

// Create a new serial interface called Serial3 using SERCOM0
// on pins PA08 (TX)(PAD0) & PA09 (RX)(PAD1).
Uart Serial3 (&sercom0, 12, 11, SERCOM_RX_PAD_1, UART_TX_PAD_0);

void SERCOM0_Handler()
{
  Serial3.IrqHandler();
}

void setup() {
  Serial3.begin(9600);
  pinPeripheral( 11, PIO_SERCOM );
  pinPeripheral( 12, PIO_SERCOM );
}

void loop() {
  Serial3.println("Hello");
  delay(1000);
}

That's the extent of my knowledge on SAMD21 and SERCOMs for now.....

Wait...
There are two I2C devices on the board: ATECC508 crypto chip and
BQ24125L battery charger. It is quite likely that they would interfere with the UART.

Having taken a further look at the schematic, the crypto, radio and battery charger are on the same I2C bus as the pins broken out onto the external connections header. I was hoping that they might use a separate I2C bus to keep them separate from user devices, but it seems not.

I wonder, however, if you can still use those signals for a UART. SCL and SDA are initially inputs on the I2C devices. SDA would only become an output if the I2C device recognised its address and responded.

If your serial comms are such that RX and TX are not active at the same time, then you may get it to work as I would imagine the timing of the data on the TX and RX lines would be such that it would be highly unlikely form the correct sequence of transitions to create an I2C start condition followed by a device address etc.

Of course, your project wouldn't be able to access those I2C devices - but not a problem if you don't use them.

markd833, thanks a lot for you help, truly appreciated.

The code you've suggested works well, I removed the TX part as I found that the scanner is not expecting any communication from the board's side, it independently sends whatever it scans. The minimum code needed is shown below.

Regarding oqibidipo comment and your conclusion, you are right again, I am not using the onboard I2C clients so no problems here as well.

#include "wiring_private.h"

Uart Serial3 (&sercom0, 12, 12, SERCOM_RX_PAD_1, UART_TX_PAD_0);

void SERCOM0_Handler() {
  Serial3.IrqHandler();
}

void setup() {
  Serial3.begin(9600);
  pinPeripheral(12, PIO_SERCOM);
}

void loop() {
  while (Serial3.available()) {
    char c = Serial3.read();
  }
}


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.