UART through RX GPIO Pin 3

AgentSmithers
Posts: 119
Joined: Sat Apr 01, 2017 1:21 am
Contact:

UART through RX GPIO Pin 3

Postby AgentSmithers » Tue Jun 05, 2018 10:26 am

Hi everyone,
On compiling this program I wrote it is able to receive UART from the live SCREEN terminal I have opened that is MicroUSB into a Wemos D1 Mini Pro. That work's fine. However I also have a UART Bridge on another port wired to RX and TX pin, I am receiving data but when I send via my bridge it does not kick off the receiving of the data on the ESP. It seem's only when I send via the Live Screen Terminal it works and not through the RX pin. However, if I short the RX and TX everything works fine and kicks off the correct INT's which makes me think It's receiving the data but not interpreting it as a byte received. Maybe the Stopbit is wrong or something I am not sure. Does anyone have any tips?
Thanks,
-Agent

https://wiki.wemos.cc/products:d1:d1_mini_pro

Code: Select all

//https://www.mikrocontroller.net/attachment/263828/The-ESP8266-Book-August-2015.pdf
#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "ip_addr.h"
#include "mem.h"
#include "user_interface.h"
#include "lwip/stats.h"
#include "espconn.h"

#include "c_types.h" ////ONE WIRE

#include "../library/uart.h" //Copy these from your Driver Lib to your local folder
#include "../library/gpio16.h" //Copy these from your Driver Lib to your local folder

#include "../library/common.h"

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

#define user_procTaskPrio        0
#define user_procTaskQueueLen    1
os_event_t user_procTaskQueue[user_procTaskQueueLen];

void uart0_tx_buffer(uint8 *buf, uint16 len);

char rxbuff[31];
char rxindex = 0;

void UartReceive(char ByteReceived)
{
   os_printf("[%s] Got UART Callback!\r\n", __func__);
   os_printf("Byte Recevied: %c\r\n", ByteReceived);

   rxbuff[rxindex++] = ByteReceived;
   if (rxindex == sizeof(rxbuff))
   {
      rxindex = 0;
   }
   else
   {
      os_printf("%d != %d\r\n", rxindex, sizeof(rxbuff));
   }
   os_printf("Buffer: %s\r\n", rxbuff);
}

void ICACHE_FLASH_ATTR sdk_init_done_cb(void)
{
   os_printf("[%s] initializing ESP8266!\n", __func__);
   while(true)
   {
      uart0_tx_buffer("test", 4);
      delay_second();
      delay_second();
   }
}

void ICACHE_FLASH_ATTR user_init()
{
   uart_init(BIT_RATE_115200, BIT_RATE_115200, &UartReceive); //This only seems to be kicked off via the COM-USB onboard, Not the TX/RX port
   //system_uart_swap(); //http://smallbits.marshall-tribe.net/blog/2016/11/13/esp8266-quiet-uart - Makes D7 RX and D8 TX
   system_init_done_cb(sdk_init_done_cb);

   wifi_set_opmode(0);
   wifi_set_sleep_type( NONE_SLEEP_T );

   ETS_GPIO_INTR_DISABLE();// Disable gpio interrupts
   gpio_init();   

   SetAllGPIOPinsAsOutput();

   /* Need to fix this to display value   */
   uint32 VDDADCByte[4] = {0};
   spi_flash_read(0x3fc06b, (uint32 *)&VDDADCByte, 1); //Read pads the other 3 bytes with FF

   os_printf("\r\n\r\nStarting ESP8266 OTA!\r\nSDK version:%s\r\nLoaded from: %02x\r\nVdd33_Const: %02x\r\n", system_get_sdk_version(), system_get_userbin_addr(), (VDDADCByte[0] & 0xff));
   //Turn off LED
   PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
   gpio_output_set((1 << 2), 0, 0, 0);

   //Start os task
   system_init_done_cb(sdk_init_done_cb);
   //system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen); //Task to Signal for later
}


Code: Select all

LOCAL void ICACHE_FLASH_ATTR uart_config(uint8 uart_no, void * callback(uint8))
{
   os_printf("uart_config:%d", uart_no);
   if (uart_no == UART1)
   {
      PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
   }
   else
   {
      /* UART0 */
      ETS_UART_INTR_ATTACH(uart0_rx_intr_handler,  callback);
      PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U);
      PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD);
      //Enable RxD pin
      //PIN_PULLUP_EN(PERIPHS_IO_MUX_U0RXD_U);
      //PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_GPIO3);      
      //PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_U0RTS);
   }

   uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate));

   if (uart_no == UART1) 
   {
      //UART 1 always 8 N 1
      WRITE_PERI_REG(UART_CONF0(uart_no), CALC_UARTMODE(EIGHT_BITS, NONE_BITS, ONE_STOP_BIT));
   }
   else
   { 
      //WRITE_PERI_REG(UART_CONF0(uart_no), CALC_UARTMODE(UartDev.data_bits, UartDev.parity, UartDev.stop_bits));
      WRITE_PERI_REG(UART_CONF0(uart_no), CALC_UARTMODE(UartDev.data_bits, NONE_BITS, UartDev.stop_bits)); //Override default settings
   }

   //clear rx and tx fifo,not ready
   SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);
   CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);

   //set rx fifo trigger
   //  WRITE_PERI_REG(UART_CONF1(uart_no),
   //                 ((UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S) |
   //                 ((96 & UART_TXFIFO_EMPTY_THRHD) << UART_TXFIFO_EMPTY_THRHD_S) |
   //                 UART_RX_FLOW_EN);
   if (uart_no == UART0)
   {
      //set rx fifo trigger to receive 0x01 byte for each call
      WRITE_PERI_REG(UART_CONF1(uart_no), ((0x01 & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S) | ((0x01 & UART_RX_FLOW_THRHD) << UART_RX_FLOW_THRHD_S) | UART_RX_FLOW_EN | (0x02 & UART_RX_TOUT_THRHD) << UART_RX_TOUT_THRHD_S | UART_RX_TOUT_EN);
      //WRITE_PERI_REG(UART_CONF1(uart_no), ((0x01 & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S) | ((0x01 & UART_RX_FLOW_THRHD) << UART_RX_FLOW_THRHD_S) | UART_RX_FLOW_EN);
      //SET_PERI_REG_MASK(UART_INT_ENA(uart_no), UART_RXFIFO_TOUT_INT_ENA | UART_FRM_ERR_INT_ENA); //This worked
      //Clear pending interrupts
      WRITE_PERI_REG(UART_INT_CLR(UART0), 0xffff);
      //enable rx_interrupt
      SET_PERI_REG_MASK(UART_INT_ENA(UART0), UART_RXFIFO_FULL_INT_ENA);
   }
   else
   {
      WRITE_PERI_REG(UART_CONF1(uart_no), ((UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S));
   }

   //clear all interrupt
   WRITE_PERI_REG(UART_INT_CLR(uart_no), 0xffff);
   //enable rx_interrupt
   SET_PERI_REG_MASK(UART_INT_ENA(uart_no), UART_RXFIFO_FULL_INT_ENA);
}

AgentSmithers
Posts: 119
Joined: Sat Apr 01, 2017 1:21 am
Contact:

Re: UART through RX GPIO Pin 3

Postby AgentSmithers » Wed Jun 06, 2018 1:05 am

So responding back I swapped out my UART board I am using with a FTDI board and things are working with my LCD screen. I haven't tested it as it pertains to my topic here but I will make it a point today.

AgentSmithers
Posts: 119
Joined: Sat Apr 01, 2017 1:21 am
Contact:

Re: UART through RX GPIO Pin 3

Postby AgentSmithers » Thu Jun 07, 2018 12:19 pm

*Flips table over* Yep, Use a FTDI chip.. Sheesh, 3 hours down the drain.
Hooking the other chip up to my DS1054 the wave it was putting out hardly looked like a square wave.

Who is online

Users browsing this forum: hizhsj and 7 guests