View previous topic :: View next topic |
Author |
Message |
DT340
Joined: 30 Jun 2015 Posts: 1
|
Posted: Tue Jun 30, 2015 2:48 pm Post subject: BASCOM software UART |
|
|
Hello,
I'm considering using BASCOM software UART for transmit only. I'm pretty new to BASCOM, so I'm not sure what the implications are with the software implementation. Could anyone tell me what kind of problems I could expect? I'm using an ATmega32 and I've had success with the hardware UART, but I need another port.
Any help at all is appreciated.
Thanks!
Sean
(BASCOM-AVR version : 1.11.9.5 , Latest : 2.0.7.8 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Jun 30, 2015 3:18 pm Post subject: |
|
|
when used as output it has little impact. the only things to keep in mind :
- an interrupt can interfere with the timing. so it might be required to disable interrupts while printing with SW UART
- there is no serial buffered output
in practice, it works out fine for most applications without worrying about the notes above. simply try it. and test it. _________________ Mark |
|
Back to top |
|
|
njepsen
Joined: 13 Aug 2007 Posts: 469
|
Posted: Mon May 01, 2017 5:33 am Post subject: |
|
|
I also am using 3 SW uarts on a ATmega 1284P, as well as the 2 HW uarts. The three SW uarts work fine, but are not as reliable as i would like. My code is below. I think the problem is one of timing - obviously. And it seems to depend on how I terminate the 'listen' loop. Because the received data varies in length, and I don't know what the last char will be, i can't look for it.
Code: | $regfile = "m1284pdef.dat" 'my processor
$crystal = 9830400 'system crystal
$framesize = 800 '
$hwstack = 550 '
$swstack = 550 '
'-------------------------------------------------------------------------------
'Open a software UART TRANSMIT channel for debug on software ser port
Open "comc.3:9600,8,n,1" For Output As #1 '
Open "comc.2:9600,8,n,1" For Input As #5
'open sw uart for raspberry pi
Open "comc.5:9600,8,n,1" For Output As #7
Open "comc.6:9600,8,n,1" For Input As #8
'Open a software UART channel for Vaisala
Open "comc.0:9600,8,n,1" For Output As #2
Open "comc.1:9600,8,n,1" For Input As #4
'--------------------------------------------------
|
Below is one of the SW uart receive loops - for a raspberry pi.
I hate the for n =10000 /next loop as a way of controlling the receive time, and I guess that adding the data to an array instead of building a string would be much faster? The biggest ser data string is 60 bytes, at 9600.
In place of the for n=/next loop, i have tried using my system syssec, and loading a variable with syssec + 2 seconds, then doing a compare of syssec with the variable, as way of terminating the receive loop, but that involves 2 Long compares, which has got to be slow. It works, but doesn't give me 100% accurate data 100% of the time.
Comments/criticism welcome.
Code: |
function Pi_response(picommand as string) as string
#if Pi_motherboard=1
local tempstr as string * 75
local j as word
for j = 1 to 10000
rxbyte = inkey(#8) '#8 is pi sw uart ser port
if rxbyte <>0 then
if len(tempstr)>= 70 then tempstr = right(tempstr,60)
tempstr = tempstr + chr(rxbyte)
end if
call housekeeping()
reset watchdog
next j
delchars tempstr,32 'remove spaces
if tempstr <>"" then
print #1, ">> Pi said:";tempstr 'my debug port
else
print #1, ">> No response from Pi"
end if
pi_response = tempstr 'return the response
#endif
end function
'****************************************************** |
_________________ Neil |
|
Back to top |
|
|
|
|
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
|
|