Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

BASCOM software UART

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions
View previous topic :: View next topic  
Author Message
DT340

Bascom Member



Joined: 30 Jun 2015
Posts: 1

PostPosted: Tue Jun 30, 2015 2:48 pm    Post subject: BASCOM software UART Reply with quote

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
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Tue Jun 30, 2015 3:18 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
njepsen

Bascom Member



Joined: 13 Aug 2007
Posts: 469

newzealand.gif
PostPosted: Mon May 01, 2017 5:33 am    Post subject: Reply with quote

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
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions 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