Serial.write problem

vitor_boss
Wed Apr 19, 2017 10:18 am
Hi, this is my first post on this forum, currently I’m help to develop Speeduino EMS/ECUand now I’m trying to convert code to Maple mini (STM32F103CBT6).

One of communication protocol use Serial.write and I’m facing problems with. Code is:
//All other bytes can simply be copied from the config table
uint8_t response[64];
//npage_size[] is an int type
for (uint16_t x = 0; x < 64; x++)
{
response[x] = *((uint8_t *)pnt_configPage + (uint16_t)(x)); //Each byte is simply the location in memory of the configPage + the offset + the variable number (x)
}

Serial.write((uint8_t *)&response, sizeof(response));


ag123
Wed Apr 19, 2017 10:38 am
try calling Serial.begin(); in setup()
when you plug the the board in the usb port, it should be detected by the os. in linux this can be viewed in lsusb command
i think in windows, you may be able to check that in the device manager

vitor_boss
Wed Apr 19, 2017 10:43 am
This is the problem, before that call the code use the same loop for a 288 bytes Serial.write and a lot of Serial.print and all work fine, only that lines aren’t giving outputs

code is at https://github.com/noisymime/speeduino/ … /comms.ino


BennehBoy
Wed Apr 19, 2017 10:51 am
Can you not just write out a single byte at a time in the loop?

I’m using Serial.write in some ecu code, but only 1 byte at a time.


vitor_boss
Wed Apr 19, 2017 11:09 am
I could test it, but that is not the point, on Mega and Teensy it works with no problem, why isn’t working with Maple mini?

BennehBoy
Wed Apr 19, 2017 11:38 am
Why is the sky blue? :D Sometimes it’s better to just get a n acceptable workaround.

stevestrong
Wed Apr 19, 2017 11:43 am
vitor, could you please explain what exactly means “it didn’t work”?
Are any bytes sent over serial? Are they wrong? Any serial monitor log available to show the problem?

I would try this way:
Serial.write(response, sizeof(response));


edogaldo
Wed Apr 19, 2017 12:06 pm
vitor_boss wrote:This is the problem, before that call the code use the same loop for a 288 bytes Serial.write and a lot of Serial.print and all work fine, only that lines aren’t giving outputs

code is at https://github.com/noisymime/speeduino/ … /comms.ino


stevestrong
Wed Apr 19, 2017 12:15 pm
If it is about this part of your code, then it will not work at least because sizeof(response) is actually not explicitly defined, but only indirectly through a variable value. So I assume you have a bug in your code.
Didn’t you have some compiler warnings?

victor_pv
Wed Apr 19, 2017 6:44 pm
stevestrong wrote:If it is about this part of your code, then it will not work at least because sizeof(response) is actually not explicitly defined, but only indirectly through a variable value. So I assume you have a bug in your code.
Didn’t you have some compiler warnings?

vitor_boss
Wed Apr 19, 2017 7:16 pm
edogaldo wrote:vitor_boss wrote:This is the problem, before that call the code use the same loop for a 288 bytes Serial.write and a lot of Serial.print and all work fine, only that lines aren’t giving outputs

code is at https://github.com/noisymime/speeduino/ … /comms.ino


vitor_boss
Wed Apr 19, 2017 7:18 pm
stevestrong wrote:vitor, could you please explain what exactly means “it didn’t work”?
Are any bytes sent over serial? Are they wrong? Any serial monitor log available to show the problem?

I would try this way:
Serial.write(response, sizeof(response));


vitor_boss
Wed Apr 19, 2017 7:25 pm
That is my software log:
19/04/17 16:16:27 :Info: Activating page: 1
19/04/17 16:16:27 :Time: 0:10.602: SENT 2 bytes iwd=10, 2 bytes
x50 x01 P.

19/04/17 16:16:27 :Time: 0:10.613: SENT 1 bytes iwd=10, 1 bytes
x56 V

19/04/17 16:16:28 :Debug: Read page time: 174ms.
19/04/17 16:16:28 :Time: 0:10.763: READ 288 bytes, 288 bytes
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................
x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 x00 ................

19/04/17 16:16:28 :Info: Activating page: 2
19/04/17 16:16:28 :Time: 0:10.785: SENT 2 bytes iwd=10, 2 bytes
x50 x02 P.

19/04/17 16:16:28 :Time: 0:10.795: SENT 1 bytes iwd=10, 1 bytes
x56 V

Time: 0:13.797: READ Timout after 0 bytes, Expected:64, actual read:0 Raw buffer
19/04/17 16:16:31 :Debug: Time:13.796s. Instruction:


vitor_boss
Wed Apr 19, 2017 7:37 pm
BennehBoy wrote:Can you not just write out a single byte at a time in the loop?

I’m using Serial.write in some ecu code, but only 1 byte at a time.


stevestrong
Thu Apr 20, 2017 9:40 am
If it works once, it should work always.
Your software is buggy.

I would suggest to get rid (remove) of sizeof(response), and use either previously defined constants or appropriate variables, where needed.
Also, define only once the “response[]” buffer of a maximum size (192?), and control the length of data as said.


victor_pv
Thu Apr 20, 2017 8:25 pm
vitor_boss wrote:
Thanks, I will try that

vitor_boss
Fri Apr 21, 2017 10:14 am
victor_pv wrote:vitor_boss wrote:
Thanks, I will try that

ag123
Fri Apr 21, 2017 10:24 am
try with Serial.write("0123456789", 10);

victor_pv
Fri Apr 21, 2017 3:46 pm
vitor_boss wrote:victor_pv wrote:vitor_boss wrote:
Thanks, I will try that

vitor_boss
Sun Apr 23, 2017 2:48 pm
victor_pv wrote:vitor_boss wrote:victor_pv wrote:

Did you try changing the line to this as I suggested?
Serial.write((byte *)&response, npage_size[currentPage]);

zmemw16
Sun Apr 23, 2017 7:51 pm
that sounds like a typical u$ enhancement of a ‘standard’ ! :o
srp

Leave a Reply

Your email address will not be published. Required fields are marked *