View previous topic :: View next topic |
Author |
Message |
mrzilek
Joined: 09 Jul 2006 Posts: 8 Location: Libeznice
|
Posted: Tue Mar 08, 2022 6:54 pm Post subject: attiny202 HW USART |
|
|
Hello,
I would like to ask if anyone has any sample code for communication over hw USART for ATTINY202, so far I haven't come across anything.
I managed to get only the software port working, but I can't set the exact speed to 19200 Bd. I am working with an internal oscillator.
Thank you for your help.
Richard
(BASCOM-AVR version : 2.0.8.5 , Latest : 2.0.8.5 ) |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Tue Mar 08, 2022 7:54 pm Post subject: |
|
|
Do you saw Sample "serial-osc.bas" in the Xtiny samples folder?
Also hit F1 in Bascom and read Help topic about "Config Comx". There is a offset that can be set for proper baud. |
|
Back to top |
|
|
mrzilek
Joined: 09 Jul 2006 Posts: 8 Location: Libeznice
|
Posted: Tue Mar 08, 2022 8:21 pm Post subject: |
|
|
I see a note here commercial addon needed. I just purchased the addon today, hopefully it will arrive tomorrow and I'll try it out. |
|
Back to top |
|
|
mrzilek
Joined: 09 Jul 2006 Posts: 8 Location: Libeznice
|
Posted: Tue Mar 08, 2022 9:05 pm Post subject: |
|
|
So my addon package for attiny has arrived.
The sample code is giving me errors, it mentions portB. But it is not in ATTINY202.
Error : 86 Line : 19 Invalid parameter for CONFIG parameter or value [16_20MHZ] , in File : C:\BASCom_AVR_last\work\Tlacitko Kovarik\sig100tlacitko.bas
Error : 46 Line : 22 Assignment error, unknown variable (DIM) [PORTB_DIRSET: 0 4: 112] , in File : C:\BASCom_AVR_last\work\Tlacitko Kovarik\sig100tlacitko.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"
$regfile = "atXtiny202.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 = 19200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1
'dimension a variable
Dim Ba As Byte
Print "Test USART"
Do
Print "Hello" ; Spc(3) ; Ba
Waitms 1000
Incr Ba
Loop
End |
|
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Tue Mar 08, 2022 9:11 pm Post subject: |
|
|
In my 2085 your code compiled just fine. On 2084 too. Maybe you dont install all addon files correctly.
|
|
Back to top |
|
|
mrzilek
Joined: 09 Jul 2006 Posts: 8 Location: Libeznice
|
Posted: Tue Mar 08, 2022 10:15 pm Post subject: |
|
|
So there really was some kind of installation error. I reinstalled Bascom and then Addon in a clean directory and now everything works as it should. The compilation went through without error.
Thank you all for your sincere efforts to help me. Just seeing that it can be compiled elsewhere helped me.
Thanks !!!
Richard |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed Mar 09, 2022 9:40 am Post subject: |
|
|
JP : i read this and had a look. yes indeed that is wrong. AVR with 128 sram normally can use only the LSB of the pointer, like R26. So there is no need to use R27 in that case. But i overlooked that for Xtiny where the memory is at a high location and the MSNB of the pointer must be set as well.
This is also true for the simulator. I will changed that asap and make an update available. Just contact support when you use an xtiny with 128 byte sram. _________________ Mark |
|
Back to top |
|
|
mrzilek
Joined: 09 Jul 2006 Posts: 8 Location: Libeznice
|
Posted: Wed Mar 09, 2022 10:49 pm Post subject: |
|
|
Hello,
I'm here with another problem regarding the ATTINY202 serial interface.
If I don't set the registers separately like this:
Usart0_baudh = &H20
Usart0_baudl = &H8D
Ucr = &HC2
Usart0_ctrlc = &H03
I get no data on the output. Just setting Config com1 ..... is not enough.
I've been working on this all day today, but nothing has worked other than setting the registries.
Does anyone know what else can be done about this please ?
Thank you Richard
Code: |
'--------------------------------------------------------------------------------
'name : serial.bas
'copyright : (c) 1995-2021, MCS Electronics
'purpose : demonstrates USART
'micro : xtiny816
'suited for demo : no
'commercial addon needed : yes
'--------------------------------------------------------------------------------
$regfile = "atXtiny202.dat"
'$regfile = "atXtiny816.dat"
$crystal = 20000000
$hwstack = 16
$swstack = 16
$framesize = 24
'$sim
'set the system clock and prescaler
Config Sysclock = 16_20mhz , Prescale = 1
'Config Port_mux = Overwrite , Usart0 = Def_pa6pa7
'configure the USART
Config Com1 = 19200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1 , Baud_offset = None ', Txpin = Def_pa6
Usart0_baudh = &H20
Usart0_baudl = &H8D
Ucr = &HC2
Usart0_ctrlc = &H03
'Config Porta.6 = Output
Do
Print "Hello"
Waitms 300
Loop
End |
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Mar 10, 2022 9:44 am Post subject: |
|
|
you best contact support@mcselec.com
the 128 ram xtiny support has a flaw. from support we can help you with an update to fix that. _________________ Mark |
|
Back to top |
|
|
|