Write to output port of ESP-WROOM-32
-
- Posts: 5
- Joined: Mon Feb 19, 2018 5:48 pm
Write to output port of ESP-WROOM-32
I am new to ESP32. Using freeRTOS in C language for my application, I notice that the chip has individual IO pins. I need to write to an LCD character module display. This devices need the computer to write to a data port (4 or 8 bits wide) plus a couple of clock lines. I can't find the way to configure a group of lines as an output por to make a byte or nibble write. Which is the correct way to do this in C ? A small piece of code as example will be very much appreciated. Thank you.
Re: WRITE TO OUTPUT PORT ESP-WROOM-32
At the highest level, one might use the GPIO APIs provided by the ESP-IDF as documented here:
http://esp-idf.readthedocs.io/en/latest ... /gpio.html
From there, one could set each of the individual bits of your data to the output pins. Once the values have been set, you could then "clock" them by toggling the clock signal. Since I think in your story the clock signal is separate from the data bus, then you shouldn't need to be super time sensitive on setting the data channels ... i.e. you wouldn't have to write multiple bits of GPIO output simultaneously.
You mechanically can do that if you drop down to the very lowest level of the ESP32 programming layers. At the lowest level there are registers where a 1 bit in the register means set the corresponding GPIO high/low. Thus you can set/clear up to 32 GPIOs pins simultaneously. However if you have a separate clock pin, I'd just loop through the bits one at a time and then toggle the clock.
http://esp-idf.readthedocs.io/en/latest ... /gpio.html
From there, one could set each of the individual bits of your data to the output pins. Once the values have been set, you could then "clock" them by toggling the clock signal. Since I think in your story the clock signal is separate from the data bus, then you shouldn't need to be super time sensitive on setting the data channels ... i.e. you wouldn't have to write multiple bits of GPIO output simultaneously.
You mechanically can do that if you drop down to the very lowest level of the ESP32 programming layers. At the lowest level there are registers where a 1 bit in the register means set the corresponding GPIO high/low. Thus you can set/clear up to 32 GPIOs pins simultaneously. However if you have a separate clock pin, I'd just loop through the bits one at a time and then toggle the clock.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
-
- Posts: 9764
- Joined: Thu Nov 26, 2015 4:08 am
Re: Write to output port of ESP-WROOM-32
Please don't use all-caps in your title. I've taken the liberty to remove them to make the topic listing less scream-y.
-
- Posts: 151
- Joined: Thu Jun 15, 2017 4:54 am
- Location: New Zealand
Re: Write to output port of ESP-WROOM-32
If it's one of the HD44780-compatible LCD displays, you could use an I2C I/O expander (PCF8574A) like this one. They are about a dollar on AliExpress.
Then you'll be able to use a library like this one which I'm using currently with a 16x2 character LCD.
Or if you want to interface the ESP32 directly with the display, you might be able to adapt this code as I did separate the I2C part from the commands, although it is 4-bit oriented and I've never tested it this way. You don't need to have all the pins synchronised as a "port" because there's usually a read/write strobe - for a write, just set up the pins as you wish, then apply the strobe. Likewise, to read, apply the strobe and then read each pin sequentially.
Then you'll be able to use a library like this one which I'm using currently with a 16x2 character LCD.
Or if you want to interface the ESP32 directly with the display, you might be able to adapt this code as I did separate the I2C part from the commands, although it is 4-bit oriented and I've never tested it this way. You don't need to have all the pins synchronised as a "port" because there's usually a read/write strobe - for a write, just set up the pins as you wish, then apply the strobe. Likewise, to read, apply the strobe and then read each pin sequentially.
Who is online
Users browsing this forum: terpstraapril, Valter and 135 guests