Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Some tip about Uno serial

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO
View previous topic :: View next topic  
Author Message
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 592

poland.gif
PostPosted: Sun Nov 13, 2016 7:02 pm    Post subject: Some tip about Uno serial Reply with quote

Hello.
For my colegue I wrote some code for ethernet nodes (Arduino Uno + shield W5100)
Program is universal because you can set each node IP, mask, gate, port for UDP, target IP, even MAC and much more with AT commands.
You simply connect it to USB and type AT+IP=192.168.1.20 or ask AT+IP?

..but then, when I send Hex to Him for program with Xloader only two of six nodes talk on serial port with terminal.

Gues what? Not all arduino bootloaders are same. They work on 115200 baud but error is big for this speed if you not use U2X
So..some bootloaders enable U2X and after program with Xloader programmed baudrate is double.

You can check this with this simple code.
I also solve problem by reseting U2X bit in my software.
Look at the errors calculations and why they enable U2X and this is propably not taken into account by Bascom.
I understand that but "this is the trap for young players" Hahaha Very Happy

Code:
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 32
$swstack = 16
$framesize = 32
$baud = 19200

Dim Reg As Byte

If Ucsr0a.u2x0 = 1 Then
 Reset Ucsr0a.u2x0     'clear bit so baud will be correct for display this message
  Reg = 1
End If

Do
 If Reg = 1 Then Print "U2X was 1" Else Print "U2X was 0"
  Wait 3
Loop
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4743
Location: Holland

blank.gif
PostPosted: Mon Nov 14, 2016 10:18 am    Post subject: Reply with quote

bascom also uses u2x when it result in a better baud. but only when the u2x is defined in that dat file.
if you do not like u2x to be set/used, you can remark the u2x constants from the dat file.

_________________
Mark
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 592

poland.gif
PostPosted: Mon Nov 14, 2016 10:26 am    Post subject: Reply with quote

I think that in my case, where my desired baud is comparatively low and compiler don`t use U2X then it stay untouched after bootloader.
I don`t have any problems with Bascom and only want inform that such a situation could happend if you want lower baudrate after bootloader set it to 115200.
This can save a day for someone Very Happy
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4743
Location: Holland

blank.gif
PostPosted: Mon Nov 14, 2016 1:43 pm    Post subject: Reply with quote

yes, it can save a day indeed. that is why i added comment about the u2x constant.
older bascom versions did not use u2x (because this options was not available in all chips). the problem arises when you have a boot loader using an older bascom version, and then compile code using a new bascom version.

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum