Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Problem UART reading data

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

Bascom Member



Joined: 08 Nov 2016
Posts: 86

PostPosted: Tue Jan 04, 2022 12:05 pm    Post subject: Problem UART reading data Reply with quote

I use ATMEGA128DB28 microcontroller and test serial interface. TX on all three ports work OK.
But when I try to recieve data, there is a problem with config serialin statement.

This error appear:

Quote:
Error : 101 Line : 24 Can't find HW-register [VPORTB_INTFLAGS ] , in File : E:\$Elektro\Projekti_MS2022\AVR128DB28TST\AVR128DB28_TST_Uart.bas
Error : 101 Line : 24 Can't find HW-register [VPORTE_INTFLAGS ] , in File : E:\$Elektro\Projekti_MS2022\AVR128DB28TST\AVR128DB28_TST_Uart.bas
Error : 101 Line : 24 Can't find HW-register [VPORTG_INTFLAGS ] , in File : E:\$Elektro\Projekti_MS2022\AVR128DB28TST\AVR128DB28_TST_Uart.bas
Error : 101 Line : 24 Can't find HW-register [PORTB_INTFLAGS ] , in File : E:\$Elektro\Projekti_MS2022\AVR128DB28TST\AVR128DB28_TST_Uart.bas
Error : 101 Line : 24 Can't find HW-register [PORTE_INTFLAGS ] , in File : E:\$Elektro\Projekti_MS2022\AVR128DB28TST\AVR128DB28_TST_Uart.bas
Error : 101 Line : 24 Can't find HW-register [PORTG_INTFLAGS ] , in File : E:\$Elektro\Projekti_MS2022\AVR128DB28TST\AVR128DB28_TST_Uart.bas
Error : 101 Line : 24 Can't find HW-register [TCA1_INTFLAGS ] , in File : E:\$Elektro\Projekti_MS2022\AVR128DB28TST\AVR128DB28_TST_Uart.bas
Error : 101 Line : 24 Can't find HW-register [TCB3_INTFLAGS ] , in File : E:\$Elektro\Projekti_MS2022\AVR128DB28TST\AVR128DB28_TST_Uart.bas
Error : 101 Line : 24 Can't find HW-register [TCB4_INTFLAGS ] , in File : E:\$Elektro\Projekti_MS2022\AVR128DB28TST\AVR128DB28_TST_Uart.bas


I think, that something is missing.

This is test code:

Code:
$regfile = "AVRX128db28.dat"

$crystal = 24000000
$hwstack = 40
$swstack = 40
$framesize = 40

'The AVRX series have more oscillator options
Config Osc = Enabled , Frequency = 24mhz
'set the system clock and prescaler
Config Sysclock = Int_osc , Prescale = 1


'configure the USART
Config Com1 = 9600 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1
Open "COM1:" For Binary As #1

Config Com2 = 9600 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1
Open "COM2:" For Binary As #2

Config Com3 = 9600 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1
Open "COM3:" For Binary As #3

Config Serialin1 = Buffered , Size = 100   'read buffer COM2 THERE is a problem !!!!!!
Enable Interrupts

'dimension a variable
Dim B As Byte


Config Portd.7 = Output


Do

   If Ischarwaiting(#2) = 1 Then
      'Gosub Read_data
   End If


   Toggle Portd.7


   Print #1, "COM1" ; Spc(3) ; B
   Print #2, "COM2" ; Spc(3) ; B
   Print #3, "COM3" ; Spc(3) ; B

   Waitms 1000
   Incr B


Loop


(BASCOM-AVR version : 2.0.8.5 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Tue Jan 04, 2022 1:20 pm    Post subject: Reply with quote

yes it is a bug you need to download the add on again. it has corrected dat files.
all files were based on the 64 pin version which has more resources. some registers were not remarked in the 28/32 pin dat files that cause this problem.

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

Bascom Member



Joined: 08 Nov 2016
Posts: 86

PostPosted: Wed Jan 05, 2022 9:19 am    Post subject: Reply with quote

Than'k you. It works now. I have one question more:
Code:

$regfile = "AVRX128db28.dat"

$crystal = 24000000
$hwstack = 40
$swstack = 40
$framesize = 40

'The AVRX series have more oscillator options
Config Osc = Enabled , Frequency = 24mhz
'set the system clock and prescaler
Config Sysclock = Int_osc , Prescale = 1

'configure the USART
Config Com1 = 9600 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1
Open "COM1:" For Binary As #1

Config Com2 = 9600 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1
Open "COM2:" For Binary As #2

Config Com3 = 9600 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1
Open "COM3:" For Binary As #3

Config Serialin1 = Buffered , Size = 100
Enable Interrupts

...


It works in all cases:

Code:
If Ischarwaiting(#2) = 1 Then
      Gosub Read_data
End If

or
Code:
If Ischarwaiting(#1) = 1 Then
      Gosub Read_data
End If

or
Code:
  If Ischarwaiting() = 1 Then
      Gosub Read_data
   End If

or
Code:
  If Ischarwaiting(#3) = 1 Then
      Gosub Read_data
   End If


My UART is connected on COM2 - pins PC0 and PC1 (config serialin1= Buffered , Size = 100)
Is there need to use MUX, or #1, #2, #3 don't have same function like using f.e. ATMEGA328?
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Wed Jan 05, 2022 1:12 pm    Post subject: Reply with quote

i do not understand what you mean.
but in your code #1 refers to com1 .in the config you can use txpin= DEF_PA0 or ALT1_PA4 so default is pa0-pa1
#2 points to com2 and txpin can be used too : DEF_PC0 or ALT1_PC4. in case txpin is not used the default is used(pc0-pc1)
etc.

when you use () without # it means the default com port which is com1

so it should work the same as with m328.
if not show an example where it behaves different.

here is some test code i used for tests

Code:

'--------------------------------------------------------------------------------
'name                     : megaX.bas
'copyright                : (c) 1995-2021, MCS Electronics
'purpose                  : demonstrates mega4809
'micro                    : mega4809
'suited for demo          : no
'commercial addon needed  : yes
'--------------------------------------------------------------------------------
'$regfile = "mx4809.dat"
$regfile = "AVRX128db64.dat"
$crystal = 24000000
$hwstack = 40
$swstack = 40
$framesize = 40

Const Ctestcom = 1                                          'use a range from 1-4 to test the COM port
Const Ctestcombuf = 1                                       'set to 1 to test buffered input

Const Ctesttca = 0                                          'set to 1 to test TCA
Const Ctestadc = 0                                          'set to 1 to test the ADC converter

Const Ctesti2c = 1                                          'set to 1 to test the master I2C
Const Ctesti2cslave = 1                                     'set to 1 to test the slave function. this requires the i2c slave add on

Config Osc = Enabled , Frequency = 24mhz
'set the system clock and prescaler
Config Sysclock = Int_osc , Prescale = 1

'optional configure the mux
'Config Port_mux = Overwrite , Usart0 = Alt1_pa4pa7 , Usart1 = None , Usart2 = Alt1_pf4pf6

#if Ctestcom = 1
   Config Com1 = 19200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1 , Txpin = Alt1_pa4
   Open "COM1:" For Binary As #1
   #if Ctestcombuf
      Config Serialin0 = Buffered , Size = 100
   #endif
#elseif Ctestcom = 2
   Config Com2 = 19200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1
   Open "COM2:" For Binary As #1
   #if Ctestcombuf
      Config Serialin1 = Buffered , Size = 100
   #endif
#elseif Ctestcom = 3
   Config Com3 = 19200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1
   Open "COM3:" For Binary As #1
   #if Ctestcombuf
      Config Serialin2 = Buffered , Size = 100
   #endif
#elseif Ctestcom = 4
   Config Com4 = 19200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1
   Open "COM4:" For Binary As #1
   #if Ctestcombuf
      Config Serialin3 = Buffered , Size = 100
   #endif
#endif

'Config Port_mux = Dummy , Spi0 = Default_pa4pa7 , Usart0 = Default_pa0pa3 , Tca0 = Default_pa0pa5

'enable the RTC
Config Clock = Soft , Rtc = 32khz_32khz_intosc
'the RTC requires that global interrupts are enabled


#if Ctesttca
   Config Porta.2 = Output                                  'wo2
   Config Tca0 = Pwm_bot , Prescale = 1 , Compare2 = Enabled , Resolution = Normal , Run = On       'začenemo timer TCA0 v t.i. "dual slope PWM" načinu na pinu PB0 (WO0)
   Tca0_per = 8000                                          'ta register določa periodo oz. frekvenco PWM; FREKVENCA PWM = 16000000/(prescale * TCA0_PER * 2) = 1000Hz; TCA0_PER = 16000000/(prescale * 1000Hz * 2) = 8000
   Tca0_cmp2 = 8000

   Do
      Tca0_cmp2 = Tca0_cmp2 + 10
      Waitms 1
   Loop
#endif


Dim S As String * 16
Dim B As Byte
Dim W As Word

Enable Interrupts

#if Ctesti2cslave
   Twi0_dualctrl = 1                                        'slave pins on separate pins
   Config Twi0slave = &H30 , Btr = 2
#endif

#if Ctesti2c
   Config Xpin = Porta.2 , Outpull = Pullup
   Config Xpin = Porta.3 , Outpull = Pullup
   Config Twi0 = 100000                                     'CONFIG TWI will ENABLE the TWI master interface
   I2cinit
   Dim Twi_start As Byte , J As Byte
   Do
      Print #1 , "Scan start"
      For J = 0 To 255
         I2cstart                                              'send start
         I2cwbyte J                                         'send address
         If Err = 0 Then                                    'we got an ack
            Print "Slave at : " ; J ; " hex : " ; Hex(j) ; " bin : " ; Bin(j)

            If J.0 = 0 Then                                    'ONLY if R/W bit is not set we may write data !!!
               I2cwbyte 100                                    'just write to values to the slave
               I2cwbyte 101
            Else                                            'read
               I2crbyte B , Ack : Print #1 , "GOT : " ; B   'read 2 bytes
               I2crbyte B , Nack : Print #1 , "GOT : " ; B
            End If

         End If
         I2cstop                                               'free bus
      Next
      Print "End Scan"
      Waitms 2000                                           'some delay and then repeat
   Loop
#endif



#if Ctestadc

'configure the internal reference to be 1v1 for both the ADC and the DAC
   Config Vref = Dummy , Adc0 = 1v1
 'configure the ADC0 to read the temp sensor
   Config Adc0 = Single , Resolution = 10bit , Adc = Enabled , Reference = Internal , Prescaler = 32 , Sample_len = 1 , Sample_cap = Above_1v , Init_delay = 32 , Mux = Tempsense

   Const _adc_kelvin = 1                                     'when reading int sensor

   Do
  'when getadc() does not have parameters, it will use the current mux setting
  'other options are : getadc(channel)  and getadc(adc0 | adc1 , channel)

      W = Getadc(&H1e) : Print #1 , "W:" ; W
      Waitms 1000
   Loop

#endif


Do
   S = Time$
   Print #1 , "1:" ; Time$
   B = Inkey(#1)
   If B <> 0 Then
      B = Waitkey(#1)
      Print "KEY:" ; B
   End If

   Print #1 , "BIN:"
   Inputbin #1 , B
   Printbin #1 , B

   If Ischarwaiting(#1) <> 0 Then
      Print #1 , "wait"
   End If

   Input #1 , "inp1" , S
Loop

#if Ctesti2cslave
'the following labels are called from the library  when master send stop or start
'notice that these label names are valid for TWIC.
'for TWID the name would be TWID_stop_rstart_received:
   Twi_stop_rstart_received:
      Print #1 , "Master sent stop or repeated start"
   Return
'master sent our slave address and will not send data
   Twi_addressed_goread:
      Print #1 , "We were addressed and master will send data"
   Return

   Twi_addressed_gowrite:
      Print #1 , "We were addressed and master will read data"
   Return
'this label is called when the master sends data and the slave has received the byte
'the variable TWIx holds the received value
'The x is the TWI interface letter
   Twi_gotdata:
      Print #1 , "received : " ; Twi0 ; " byte no : " ; Twi0_btw
   'here you would do something with the received data
   '   Select Case Twic_btw
   '     Case 1 : Portb = Twi                                   ' first byte
   '     Case 2:                                                'you can set another port here for example
   '   End Select
   Return

'this label is called when the master receives data and needs a byte
'the variable twix_btr is a byte variable that holds the index of the needed byte
'so when sending multiple bytes from an array, twix_btr can be used for the index
'again the variable name depends on the twi interface
   Twi_master_needs_byte:
      Print #1 , "Master needs byte : " ; Twi0_btr
      Select Case Twi0_btr
         Case 1:                                                 ' first byte
            Twi0 = 66                                          'we assign a value but this could be any value you want
         Case 2                                                ' send second byte
            Twi0 = 67
      End Select
   Return

'when the mast has all bytes received this label will be called
   Twi_master_need_nomore_byte:
      Print #1 , "Master does not need anymore bytes"
   Return

#endif

End



about portmux : you can use it. but take care : i would not use it together with the TXPIN option. also, the TXPIN option is more clear about configuration for that usart. but that is my opinion.

_________________
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-AVR 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