View previous topic :: View next topic |
Author |
Message |
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Fri Jul 23, 2021 3:42 pm Post subject: ATTINY1604 serial port |
|
|
This is my first try at ATTINY1604 serial communication.
I'm testing out the hardware and software serial communications by sending 4 bytes at 38400 baud.
(one gets remarked out while testing the other)
Problem 1:
Printbin sends proper message, except at 600 baud (regardless of baud in Config Com1)
Problem 2:
Serout doesn't do anything (pin starts low, stays low)
Is there something simple I'm overlooking?
Thanks much!
Code: | $regfile = "atxtiny1604.dat" ' ATTINY1604
Config Sysclock = 16_20mhz , Prescale = 2 : $crystal = 10000000 ' 10 Mhz
Config Submode = New
$baud = 38400
Config Com1 = 38400 , Parity = None , Stopbits = 1 , Databits = 8 , Baud_offset = None , Txpin = Alt1_pa1 ' RS485 port
Config Print = Porta.3 , Mode = Set ' RS485 TX enable
' Config Serialin = Buffered , Size = 4 ' RS485 port Rx buffer
' Config Serialout = Buffered , Size = 4 ' RS485 port Tx buffer
' $timeout = 1000000 ' serial port timeout
$hwstack = 40 ' hardware stack size
$swstack = 40 ' software stack size
$framesize = 100 ' frame size
'Port A
Config Porta = &B00111010
Tx0 Alias Porta.1
Rx0 Alias Pina.2
Tx0_enable Alias Porta.3 : Reset Tx0_enable
Dim Rx0_buffer(4) As Byte
Dim Tx0_buffer(4) As Byte
' test message
Tx0_buffer(1) = &HFF
Tx0_buffer(2) = &H00
Tx0_buffer(3) = &HFF
Tx0_buffer(4) = &H00
Enable Interrupts
Main_loop:
Printbin Tx0_buffer(1) , 4 ' transmit message (hardware)
' Set Tx0_enable
' Disable Interrupts
' Serout Tx0_buffer(1) , 4 , Porta , 1 , 38400 , 0 , 8 , 1 ' transmit message (software)
' Enable Interrupts
' Reset Tx0_enable
Wait 1
Goto Main_loop
|
(BASCOM-AVR version : 2.0.8.4 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Jul 23, 2021 8:34 pm Post subject: |
|
|
1: you best use a simple sample. i always start with the real simple serial.bas
Code: | 'name : serial.bas
'copyright : (c) 1995-2021, MCS Electronics
'purpose : demonstrates USART
'micro : xtiny816
'suited for demo : no
'commercial addon needed : yes
'--------------------------------------------------------------------------------
$regfile = "atXtiny816.dat"
$crystal = 20000000
$hwstack = 16
$swstack = 16
$framesize = 24
'set the system clock and prescaler
Config Sysclock = 16_20MHZ , Prescale = 1
'configure the USART
Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1
'dimension a variable
Dim B As Byte
Print "Test USART"
Do
Print "Hello" ; Spc(3) ; B
Waitms 1000
Incr B
Loop
End |
- note that $baud is not recommend any longer. you best use config com
- you can try with the default pin used for output but the alternative pin should work equal well
- always establish if the frequency specified with $crystal is actually the running freq. (look up other posts that toggle portb)
- try to leave out other commands and configurations
2: make sure you have an updated version of the add on that matches 2084. in lib manager the lib history will show ; history = 2084.001, serin/serout support added
an update you can get from register.mcselec.com
you can also use 2084 option update for add ons (update addon) _________________ Mark |
|
Back to top |
|
|
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Sat Jul 24, 2021 12:27 am Post subject: |
|
|
Quote: | 1: you best use a simple sample. i always start with the real simple serial.bas |
Code: | $regfile = "atxtiny1604.dat" ' ATTINY1604
Config Sysclock = 16_20mhz , Prescale = 2 : $crystal = 10000000 ' 10 Mhz
Config Submode = New
Config Com1 = 9600 , Parity = None , Stopbits = 1 , Databits = 8 , Baud_offset = None , Txpin = Alt1_pa1 ' RS485 port
Config Serialout0 = Buffered , Size = 4 ' RS485 port Tx buffer
$hwstack = 40 ' hardware stack size
$swstack = 40 ' software stack size
$framesize = 100 ' frame size
Config Porta.1 = Output ' alt TX
Config Portb.2 = Output ' def TX
Config Portb.3 = Output ' LED
Led Alias Portb.3
Dim Tx0_buffer(4) As Byte
Enable Interrupts
Tx0_buffer(1) = &HFF
Tx0_buffer(2) = &H00
Tx0_buffer(3) = &HFF
Tx0_buffer(4) = &H00
Main_loop:
Printbin Tx0_buffer(1) , 4
' Print "ABCD"
' Serout Tx0_buffer(1) , 4 , Porta , 1 , 9600 , 0 , 8 , 1 , Inverted
Toggle Led
Waitms 250
Goto Main_loop
End |
Quote: | - note that $baud is not recommend any longer. you best use config com |
removed $baud, kept config com1
Quote: | - you can try with the default pin used for output but the alternative pin should work equal well |
same results on PB2, PA1
Quote: | - always establish if the frequency specified with $crystal is actually the running freq. (look up other posts that toggle portb) |
1. fuse is set for 20Mhz
2. I setup a 38Khz 50% wave based on 20Mhz/Prescale=2 and verified output is 38Khz/50%
Code: | Config Tcb0 = Pwm , Prescale = 2 , Run = On , Ccmp_output = Enabled
Tcb0_ccmp = 17026 ' 66, 131
|
Quote: | - try to leave out other commands and configurations |
did that as much as possible
Quote: | 2: make sure you have an updated version of the add on that matches 2084. in lib manager the lib history will show ; history = 2084.001, serin/serout support added
an update you can get from register.mcselec.com
you can also use 2084 option update for add ons (update addon) |
XTINY 2.0.8.4
RESULTS:
Printbin and Print output correct data on both pins at 600bps regardless of Config Com1 baud setting.
Serout outputs correct data at correct baud rate on both pins.
Maybe a bad chip???
Thanks, Mark. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Sat Jul 24, 2021 7:06 am Post subject: |
|
|
as simple as possible means also without the interrupt and buffered mode.
you have a problem with the uart right? so the best thing is to start with the simple mode as i posted before.
then when it is still the same, print the hex values (in the simulator) of the USART registers.
USART0_BAUDH
USART0_BAUDL
USART0_CTRLA
USART0_CTRLB
USART0_CTRLC
and give more info about your hardware. and the programmer you use.
when serout works it means you are using the right clock settings.
odd is that there is a factor 16 between baud and actual baud _________________ Mark |
|
Back to top |
|
|
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Sat Jul 24, 2021 6:14 pm Post subject: |
|
|
Quote: | as simple as possible means also without the interrupt and buffered mode. |
I remarked out Config Serout0 and Enable Interrupts, same result
simulator results:
USART0_BAUDH = &h00
USART0_BAUDL = &h00
USART0_CTRLA = &h00
USART0_CTRLB = &hC0
USART0_CTRLC = &h03
Quote: | and give more info about your hardware. and the programmer you use. |
Atmel ICE programmer (2x3 50mil header)
Microchip Studio
PCB schematic attached
Quote: | odd is that there is a factor 16 between baud and actual baud |
not quite the case: all baud rates (38400, 19200, 9600) all put out 600bps
In light of the sim values above, I added this line before Main_loop:
Code: | Usart0_baud = 1042 ' 38400 bps
' Usart0_baud = 4167 ' 9600 bps
' Usart0_baud = 2083 ' 19200 bps |
Serial port is now working for all baud rates. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Sat Jul 24, 2021 8:02 pm Post subject: |
|
|
you forgot to specify the mode : Mode = Asynchroneous
if you do not specify mode the baud will not be set. _________________ Mark |
|
Back to top |
|
|
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Sun Jul 25, 2021 4:23 am Post subject: |
|
|
Quote: | you forgot to specify the mode : Mode = Asynchroneous |
I assumed I could leave out options that don't need to change - asynch is the default setting for the Control C register.
Never assume anything !!!
Thanks for the help !! |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Mon Jul 26, 2021 8:47 am Post subject: |
|
|
yes normally that would be true and it is for almost all parameters.
but since the mode is important for the baud calculation, it must be provided. _________________ Mark |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Mon Jul 26, 2021 8:53 am Post subject: |
|
|
and from the help for config com xtiny :
It is preferred to use CONFIG COM instead of using $BAUD.
[PICTURE notice.jpg]It is important that you specify all parameters of CONFIG COM. Do not omit one. The only optional parameter is TXPIN for the alternative TX pin. _________________ Mark |
|
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
|
|