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).
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 .
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.
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.