Connecting 3 uart peripherals with esp32 - max

I have 3 devices(GPS-Rx only, tft display-TxRx and a motor driver-Rx only) that connect only using uart. 2 of which only Tx, while one another has both Tx and Rx. I am using uart 0, for tx-rx peripheral. Flash mode and peripheral usage with device are separated with a push switch.
I also have a micro sd card requirement, so pins of uart1 has to be changed from spi pins.
I am using esp-idf and I am trying to use uart_set_pin. Now I have 2 questions,
How do I set no pin for Tx? Setting "UART_PIN_NO_CHANGE" would set it only to default Tx pin.
Can I use GPIO 16 and 17 for Rx pins of uart1 and uart2 respectively?

Related

Unable to init uart with micropython & ttl to rs485

I'm using a board with the next GPIO as the image:
Also im ussing a TTL to RS-485 module at 5V with chipset MAX485.
ESP32
MAX485
RX
DI
TX
RO
15
DE & RE
When I add the line to init uart, the board doesn't reply more.
from machine import UART
print("hello")
uart = UART(1,baudrate=9600, bits=8, parity=None, stop=1, rx=3,tx=1)
print("bye")
As anyone know about what I'm doing bad?
many thanks
Seems that board shares the tx+rx pins 1&3 with the usb debug, cause of that i lost my com with the esp32 and is the cause of "no response"

Linux I2C custom message frame sending

Is it possible to send out a custom message frame on I2C dev from Linux? I am using an i.MX7D board and i would like to use "/dev/i2c-0" device like a simple "serial tty" to "write(fd, bytes, count)". My goal is to send out a single byte for example 0xAB on I2C without any specific slave address and without automatic stop/start bit inserting in my frame.
So i like to make my full custom I2C frame then send it out from Linux. Is it possible, is there any user-space programing techniques in C/C++, Python or any API for it in Linux?
No you can't, because this is limited by the hardware, if you are using the I2c interface, the hardware will limit what you can do.
One way to try is that you can use gpio to simulate i2c or any interface you want to. Many chips support setting the i2c interface to gpio, then you simulate a clock with one gpio, and simulate high and low level with another gpio.
But I don't recommend it, because if you don't follow the i2c protocol, you can't communicate with other i2c devices
Connect two GPIO lines to the I2C bus in addition to the I2C interface. Normally, these will stay tri-stated. When you need to send the magic byte, enable them to send clock and data, then disable them. These won't interfere with I2C, which only drives the bus when transmitting.

Esp32 Micropython Max31865 Spi connection and data read

I need to read temperature data with using MAX31865 SPI communication. First of all, I tried to read 4 byte data:
import machine
import ubinascii
spi = machine.SPI(1, baudrate=5000000, polarity=0, phase=0)
#baudrate controls the speed of the clock line in hertz.
#polarity controls the polarity of the clock line, i.e. if it's idle at a low or high level.
#phase controls the phase of the clock line, i.e. when data is read and written during a clock cycle
cs = machine.Pin(15, machine.Pin.OUT)
cs.off()
cs.on()
data = spi.read(4)
cs.off()
print(ubinascii.hexlify(data))
I tried many times with different codes but result is always similar b'00000000'.
I am using ESP32 WROOM.
I used this pins:
ESP32 : D12 - D14 - 3V3 - GND - D15
Max31865: SDO - CLK - VIN - GND - CS
I am new on micropython and esp32.
I don't know what should I do. Is there any suggestions , recommended tutorials or idea?
Short answer: see if you can use CircuitPython and its drivers for MAX31865.
Long answer: a bunch of stuff. I suspect you've been following the Adafruit tutorial for MAX31855, but its SPI interface is very different from the MAX31865.
Your SPI connection is missing the SDI pin. You have to connect it, as communication is bidirectional. Also, I suggest using the default SPI pinout on ESP32 side as described in the micropython documetation for ESP32.
The SPI startup looks to be missing stuff. Looking at the SPI documentation a call to machine.SPI() requires that you assign values to arguments sck, mosi, miso. Those would probably be the pins on ESP32 side where you've connected SCLK, SDI, SDO on MAX31865 (note mosi means "master out, slave in" and miso is "master in, slave out").
The chip select signal on the MAX is inverted (that's what the line above CS input in the datasheet means). You have to set it low to activate the chip and high to disable it.
You can't just read data out of the chip, it has a protocol you must follow. First you have to request a temperature-to-resistance conversion from the chip. The datasheet for your chip explains how to do that, the relevant info starts on page 13 (it's a bit difficult to read for a beginner, but try anyway as it's the authoritative source of information for this chip). On a high level, it works like this:
Write to Configuration register a value which initiates the conversion.
Wait for the conversion to complete.
Read from the RTD (Resistance-To-Digital) registers to get the conversion result.
Calculate the temperature value from the conversion result.
The code might be closer to this (not tested, and very likely to not work off the bat - but it should convey the idea):
import ubinascii, time
from machine import Pin, SPI
cs = Pin(15, Pin.OUT)
# Assuming you've rewired according to default SPI pinout
spi = machine.SPI(1, baudrate=100000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
# Enable chip
cs.off()
# Prime a 1-shot read by writing 0x40 to Configration register 0x00
spi.write(b'\x00\x40')
# Wait for conversion to complete (up to 66 ms)
time.sleep_ms(100)
# Select the RTD MSBs register (0x01) and read 1 byte from it
spi.write(b'\x01')
msb = spi.read(1)
# Select the RTD LSBs register (0x02) and read 1 byte from it
spi.write(b'\x02')
lsb = spi.read(1)
# Disable chip
cs.on()
# Join the 2 bytes
result = msb * 256 + lsb
print(ubinascii.hexlify(result))
Convert result to temperature according to section "Converting RTD Data Register
Values to Temperature" in datasheet.
Side note 1: here spi = machine.SPI(1, baudrate=5000000, polarity=0, phase=0) you've configured a baud rate of 5MHz which is the maximum for this chip. Depending on how you've connected your devices, it may not work. The SPI protocol is synchronous and driven by master device, so you can set any baud rate you want. Start with a much, much lower value, maybe 100KHz or so. Increase this after you've figured out how to talk to the chip.
Side note 2: if you want your conversion result faster than the 100ms sleep in my code, connect the DRDY line from MAX to ESP32 and wait for it to go low. This means the conversion is finished and you can read out the result immediately.

What enables the Raspberry Pi GPIO15(RXD0) pull-up resistor during boot?

On the raspberry pi 3 all GPIO pins are powered up with a direction of "input". Each pin has a pull-up and a pull-down resistor associated with it. The status of these resistors is preserved through power loss or reset. (This is why there is no way to read the status of these resistors because they may not be known after a reset.)
I wrote a program that forces all the pull resistors to disabled so that nothing is pulling the lines high or low and then rebooted. /sys/class/gpio/*/direction and values all indicate success.
After reset, all pins came up in the input direction and without pull resistors enabled except for:
GPIO2: pulled-up (No problem, due to externally soldered i2c pull-up
resistor)
GPIO3: pulled-up (No problem, due to externally soldered i2c pull-up resistor)
GPIO14: (TXD0) pull-down resistor has been re-enabled somehow!
GPIO15: (RXD0) pull-up resistor has been re-enabled somehow!
I have already previously used raspi-config to disable both the serial console logging and the serial uart. So I would think nothing in the boot process should alter the peripheral registers controlling GPIO14 and GPIO15.
What in the boot process is reconfiguring the GPIO15(RXD0) and GPIO14(TXD0) pins to have their pull-up/down resistors enabled and how to I stop it?
One thing I found out:
The pull-up/down resistor configurations on the broadcom chipset are non-volatile. (This is actually why you can't query what their status is in anyway; because the chip doesn't know what they are from boot time and can't query them itself. The CPU can only set them.)
So, if you turn off all the pull-up/down resistors the raspian distribution boots with all pins in the output/high-z configuration except for GPIO2 and 3 because these are the I2C pins with physical pull-up resistors soldered on board. The Tx GPIO pin also reads high but I think it due to the bluetooth system being initialized in the kernel and I don't know how to disable that.
So if you set all the pins to input/hi-z and disable pull-up/pull-down it will come up that way after reboot (unless you've enable something in the kernel or otherwise changed them after power-up)

How can I use HPS pins of altera FPGA development board?

How can I design my own MAC layer function to access Ethernet chip instead of using altera IP function. My board is DE1-SoC with cyclone V 5CSEMA5F31C6 chip. The pins to access Ethernet chip are made to be HPS pins which I can't assign my own signals to.
It is possible for Cyclone V as well. I have my own Ethernet IP working on the fpga side in a DE1-SOC board using the HPS pins. I used them through the pin multiplexing feature of the hps component. You have to configure them and make the hps boot the preloader code for that configuration. However, you cannot use the DDR feature (consequently you cannot achieve 1Gbps) in the cyclone v (Altera said that).
For the process, you should set the pin multiplexing, generate Qsys and compile Quartus. This process creates the folder spl_bsp. Then you have to create a SD card with the image provided by Altera (the image contains all the partition requiered). After this you are able to make the preloader:
1) bsp-generate-files.exe --settings ./software/spl_bsp/settings.bsp --bsp-dir ./hps_isw_handoff/soc_system_hps_0
2) cd software/spl_bsp/
3) make
4) make uboot
5) alt-boot-disk-util.exe -p preloader-mkpimage.bin -a write -d e // e is the drive of the SD card
6) cp uboot-socfpga/u-boot.img /cygdrive/e
Finally, put the SD card in the fpga kit and programm the FPGA. The HPS boots from the SD card and the pin multiplexing matrix configures the pins for output.
This is possible on the new Arria 10 SoC, but not in Cyclone V. Arria 10 has shared I/Os that are configurable to the HPS or the FPGA.

Resources