Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] {ESP8266} Can not transmit zero with Serial.write if using Serial.swap

Status
Not open for further replies.

dhruv_electro

Advanced Member level 4
Joined
Dec 17, 2010
Messages
118
Helped
9
Reputation
18
Reaction score
8
Trophy points
1,298
Location
India
Activity points
2,378
Hardware
Hardware: ESP-12E
Core Version: 2.3.0

Settings in IDE
Module: Generic ESP8266 Module (ESP-12E)
Flash Size: 4MB/1MB
CPU Frequency: 80Mhz
Flash Mode: qio
Flash Frequency: 80Mhz
Upload Using: SERIAL
Reset Method: nodemcu

System Setup
I am using ESP-12E, a separate power supply and programing it with Serial to TTL in Arduino Eclipse Plug-in called Sloeber. I am using terminal.exe as my Serial Monitor. I have connected second Serial To TTL on D15-D13, for Serial.swap() UART.

Problem Description
I want to use Serial.swap() and send my application data on D15-D13 after boot-up in binary form. But after Serial.swap(), it can not send 0x00 data on UART. I have tried two sketches, which involves cases of not using and using of "Serial.swap()". I tried to send 0x00 0x01 0x02 in loop in both cases. Codes and Outputs are as follows:

Sketch 1 (successful)
Code:
//The setup function is called once at startup of the sketch
void setup()
{
   Serial.begin(115200);
}

// The loop function is called in an endless loop
void loop()
{
   for(uint8_t i=0;i<3;i++)
   {
      Serial.write(i);
      delay(1000);
   }
}

Output at terminal.exe in HEX mode
Code:
00 01 02 00 01 02 00 01 02 00 01 02

Sketch 2 (problem)
Code:
//The setup function is called once at startup of the sketch
void setup()
{
   Serial.begin(115200);

   // Swap serial port to continue on other uart.
   Serial.swap();
}

// The loop function is called in an endless loop
void loop()
{
   for(uint8_t i=0;i<3;i++)
   {
      Serial.write(i);
      delay(1000);
   }
}

Output 2 in terminal.exe in Hex mode
Code:
01 02 01 02 01 02 01 02

The problem is when I use Serial.swap() it does not send the 0x00 data on UART. Am I missing something? Please help.
 

Looks like you are trying to send null-terminated string. This is obviosly possible only if this string not including zeroes. That's why.
 

Looks like you are trying to send null-terminated string. This is obviosly possible only if this string not including zeroes. That's why.

I think you are confused with my question. I am not sending Null-terminated string. I am sending bytes 0x00 0x01 0x02 (uint8_t) with UART. And as byte will have value from (0 to 255) or (0x00 to 0xFF). It should send 0x00, which it is sending in first case i.e. sketch 1 successfully. It does not send 0x00 when I use Serial.swap(). That is the problem.
 

Yes, this one I found. But it is useless:
Code:
void HardwareSerial::swap(uint8_t tx_pin)
{
    if(!_uart) {
        return;
    }
    uart_swap(_uart, tx_pin);
}
What should uart_swap do?
 
Yes, this one I found. But it is useless:
What should uart_swap do?

Thanks for the interest, yes this goes to **broken link removed**

Code:
void uart_swap(uart_t* uart, int tx_pin)
{
    if(uart == NULL) {
        return;
    }
    switch(uart->uart_nr) {
    case UART0:
        if(((uart->tx_pin == 1 || uart->tx_pin == 2) && uart->tx_enabled) || (uart->rx_pin == 3 && uart->rx_enabled)) {
            if(uart->tx_enabled) { //TX
                pinMode(uart->tx_pin, INPUT);
                uart->tx_pin = 15;
            }
            if(uart->rx_enabled) { //RX
                pinMode(uart->rx_pin, INPUT);
                uart->rx_pin = 13;
            }
            if(uart->tx_enabled) {
                pinMode(uart->tx_pin, FUNCTION_4);    //TX
            }
            if(uart->rx_enabled) {
                pinMode(uart->rx_pin, FUNCTION_4);    //RX
            }
            IOSWAP |= (1 << IOSWAPU0);
        } else {
            if(uart->tx_enabled) { //TX
                pinMode(uart->tx_pin, INPUT);
                uart->tx_pin = (tx_pin == 2)?2:1;
            }
            if(uart->rx_enabled) { //RX
                pinMode(uart->rx_pin, INPUT);
                uart->rx_pin = 3;
            }
            if(uart->tx_enabled) {
                pinMode(uart->tx_pin, (tx_pin == 2)?FUNCTION_4:SPECIAL);    //TX
            }
            if(uart->rx_enabled) {
                pinMode(3, SPECIAL);    //RX
            }
            IOSWAP &= ~(1 << IOSWAPU0);
        }

        break;
    case UART1:
        // Currently no swap possible! See GPIO pins used by UART
        break;
    default:
        break;
    }
}

- - - Updated - - -

Please also refer this **broken link removed** object.
 

You just showed how the function was made, but did not answered Easyrider83's question:
What is supposed the uart_swap() function to do ? What do you expect on using it ?
 

You just showed how the function was made, but did not answered Easyrider83's question:
What is supposed the uart_swap() function to do ? What do you expect on using it ?

I think I have given the reference of **broken link removed**. But let me put it here also

Serial uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3 (RX). Serial may be remapped to GPIO15 (TX) and GPIO13 (RX) by calling Serial.swap() after Serial.begin. Calling swap again maps UART0 back to GPIO1 and GPIO3.

Again thanks for the reply.
 

It should have been named serial.remap() instead of serial.swap().
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top