So I have connected a Software serial on the ESP (pins 4 and 5) TO TX2 and RX2 (PA2 and PA3). I am assuming this is a hardware uart.
As I am sending various messages with a header character, rather than set up a state machine, I accumulate all characters until a CR as a “phrase” of text to then break up into meaninful bits.:
this is the code I am using:
bool serial1Event(void) //NEEDS TO RESPOND TO SERIAL1
{
char d = (char) Serial1.read();//convert d into char
//Serial.print(d);
if(d == '\n')
return false;
if(d == '\r' ) // look for the carriage return
return true; //set complete flag to true.
else
strncat(ser_in_chrs,&d,1); //concantenate it, d isn't null terminated. so only 1 char.
return false;
}
Raj
@Raj
And that is the issue…
You do not know. I would suggest isolating the issue and then attempt to correct. You can use a USB to serial adapter and your PC with a terminal program to isolate. Start with the ESP8266 and send the commands manually using the terminal emulator. Do you get back what you expect? Same action with the STM32.
This is not an unusual situation when you are working with a parser and serial comms. I built a device simply for this very purpose here.
Parsing sounds simple until one gets into the reality of having to deal with a stream of characters… even blocking on /cr /lf can be problematic. I have been successful with a few projects doing my own parsing:
http://www.hackster.io/rayburne/tardis- … server-gps
http://www.hackster.io/rayburne/gps-clo … t-for-psoc
http://www.hackster.io/rayburne/scientific-calculator
https://github.com/rogerclarkmelbourne/ … arsing.ino
Note, the examples are not intended on being very efficient … they are more for projects directed to a general Arduino audience… not power users!
Essentially, your receiving code just needs to discard and reprocess when it receives garbage.
A simple example on the Nano:
Serial.readBytes( Inst, 4);
Operation = Inst; Operation.trim();
for ( j= 0; j<operations; j++) {
if (Operation.equalsIgnoreCase(sStack[j])) {
T0 = millis();
// Serial << "found " << sStack[j] << " index =" << j << "\n\n" ;
break;
}
}
switch (j)
{
case 0:
To answer some of your question: yes it works fine when I interrogate the esp with my computer serial port.
I am still testing the other way around.
I will have to investigate start-stop-parity bits for the serial side and maybe even see if there is a way of getting DTR and RTS signals to increase the accuracy.
Now that I think about it, a checksum is a must I guess.
Its been a while since I did this kind of thing so I’d forgotten about it. Thanks for reminding me.
I was just wondering if I’d reached the limit of the chip capability and if the serial1 port as the chip is doing a lot of other stuff and using libraries that a probably interrupt driven. I was also trying to figure out why it was the first few bytes an the rest of the serial info seemed ok.
I am working at 9600baud, but I intend to go a lot faster as there is a lot of information to transmit.
WIth a CRC or checkup I can as for a resend…
At least I know where to start. Thanks :8)
<…>
I was just wondering if I’d reached the limit of the chip capability and if the serial1 port as the chip is doing a lot of other stuff and using libraries that a probably interrupt driven. I was also trying to figure out why it was the first few bytes an the rest of the serial info seemed ok.
I am working at 9600baud, but I intend to go a lot faster as there is a lot of information to transmit.
WIth a CRC or checkup I can as for a resend…
At least I know where to start. Thanks :8)
i was thinking that in addition to sending fixed data at fixed baud rates and having the ability to increase/decrease baud that adding add checksum, inc/decrease start stop bits and turn on CRC 8, 16 32 (there is a nice crc library by Paul Stoffregen, but I don’t know it it will work on an esp or stm) would be a good idea? I have some 3.3v pro minis that I might try and a couple of TFTs to experiment with.
If it does work, an Auto Train protocol would be nice, but well beyond what I can do from a programming point of view. Until that moment I will just have to hack it.
I suppose I also have to read up on communications in noisy environments.
As far as embarrassment goes I suppose I’ve been through that already when I posted to Arduino.cc where they encourage you to post all your code, so I did and had it picked apart by a moderator there. I really didn’t understand pointers then – I understood the concept it’s just the syntax that was throwing me (still throws me). So when I posted up my bodged code just “to get things to bloody work I don’t care how dirty it looks” it was seized up on. I took it on the chin – and thought I was man enough to take it. But only now did I realise that 3 months had elapsed before I did any more programming.
Thanks again for giving me a guiding hand. Knuckling out a problem is the only way to learn.
<…>
As far as embarrassment goes I suppose I’ve been through that already when I posted to Arduino.cc where they encourage you to post all your code, so I did and had it picked apart by a moderator there. I really didn’t understand pointers then – I understood the concept it’s just the syntax that was throwing me (still throws me).
i.e if you are using the bootloader and have USB serial.
Then Serial is USBSerial
Serial1 is HW serial 1 on PA9 and PA10
Serial2 is HW Serial 2 (I can’t remember what pins this is on, possibly PA2 and PA3 but you’d need to check)
Please check which HW serial port you are actually using and which pins are used by that port
I am using:
So I have connected a Software serial on the ESP (pins 4 and 5) TO TX2 and RX2 (PA2 and PA3).
I have 2 CP2102s on my PC one for each device.
So when I say Serial.print – am I defo using PA9 PA10
and Serial1.print which one am I using then? I expect to be using PA2 PA3.
As I am getting something, is that proof that I have wired up correctly?
Raj
BTW. WIndows driver does work, including on WIndows 10..
But if you are not using the bootloader
Serial – HW Serial 1
Serial1 HW Serial 2
(Sorry I can’t remember which pins these are on, you’d need to consult STM’s own docs or look in the core code for the variant board you are using (STM32F103C) )
If you have tested Serial1.print to a USB to serial adaptor connected to your PC and that is working as expected, but the ESP8266 is not responding, then the issue is likely to be the ESP8266
Have you checked if Software serial is available on all pins i.e is it available on the pins you are using
Also I think you connected your Software serial from ESP pins to the usb to serial and checked thats working on your PC.
Is TX connected to RX etc etc
I struggled a lot before with programming with the usb and installing the driver. However I would like to give it another go.
Is there a how to page I can walk through the procedure again, It is a ton more convenient and it also means I can update firmware once the thing is installed inside a box ready for use.
Raj
There is a installer bat file in /drivers/win
Run that, and accept the prompts as it has to admin stuff to install driver certificates (that the exe generates)
Flash the bootloader (via serial).
Then look in your device manager.
You will probably see a Maple DFU device, as there will be no code for it to run as the bootloader will have overwritten your existing code
If the device is not recognized, look in the /driver/win folder and the installation process will have added 2 new folders (not src or win_xp_legacy) – Sorry I can’t remember the folder name, but they could be “Maple DFU” and “Maple Serial”
Anyway, if the driver for the DFU device isnt recognized, go into that device, and select the button to update the driver and select that you want to browse for a file for the driver, then select the appropriate folder, and try reloading the driver
That normally works.
Now upload a blank sketch, and the device manager should show the Maple Serial device. If this is not recognized, do the same as before…
Note. The Bootloader DFU device and the Maple Serial device do not run at the same time, the Maple Serial code is compiled as part of the sketch its not part of the bootloader
Also make sure you select the correct board type and correct upload mode e.g. bootloader
As noob I struggled to find the information and the first place I looked was in this board.
The other thing I would make sticky is this post: (at least the explanatory post by freddbox)
viewtopic.php?f=27&t=690&p=8049#p8049
that was very helpful since the driver didn’t load.
I think this would save a lot of questions in the future…. just my 2
I used a fresh blue pill mini this time with bootloader intact.
Its a shame really
My sketch currently uses 83% of available ram (128k), probably because I am using a lot of UCGlib fonts(something I’ve decided to redo). But it doesn’t reboot when I press the reboot button. Is that bad? Yes I know its bad because it means the sketch doesn’t load on power reset as so I will have to figure out why. For a datalogger, not surviving reset is a terminal problem.
I had a similar problem when I ported it to the ESP8266 (which is one reason I went to the 2 chip option). I am using the hardware SPI to run a 320×240 TFT touch screen (still working on the touchscreen code as I can’t get the touch libraries to work only XPT2024 sketch that I found here).
My sketch currently uses 83% of available ram (128k).
What board are you using, does it have a LED on the board
The bootloader will flash the LED, if it doesnt flash then the loader is not working

