Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Usart problem on ATxmega384C3

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

Bascom Member



Joined: 07 Jul 2011
Posts: 114

PostPosted: Fri Feb 08, 2019 12:47 am    Post subject: Usart problem on ATxmega384C3 Reply with quote

Hello,

I'm use the Xmega384C3 to communicate to a HM11 Bluetooth module

If i send the command Print #5 , "AT+DISC?" from a computer with serial adapter, the HM11 understand every time the commnd and respond correctly,
but if send the same command trough the microcontroller, it works only one or two times

Can anyone help?
What make i wrong?
This is the code for setup the Usart and Timer

'****************************** Usart for HM11 *********************************
' portE.2/portE.3 - to BLE HM11
Config Com5 = 9600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Open "Com5:" For Binary As #5
Config Serialin4 = Buffered , Size = 70
'*******************************************************************************
'***************************** TIMER ******************************
Config Priority = Static , Vector = Application , Lo = Enabled ' , Med = Enabled , Hi = Enabled
'Timer C0
Config Tcc0 = Normal , Prescale = 1024
Tcc0_per = 31250
On Tcc0_ovf acorda 'Setup overflow interrupt do Timer/Counter C0
Enable Tcc0_ovf , Lo 'Activa overflow interrupt em LOW Priority
'******************************************************************

Best regards and thanks for help

P_Santos

(BASCOM-AVR version : 2.0.8.1 )
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri Feb 08, 2019 1:04 am    Post subject: Reply with quote

By default, after Print command Bascom add <CR><LF>
If you add semicolon at the end then those two characters will not be added. Then you can add one of them yourself.
Try one of this commands:
Code:
Print #5 , "AT+DISC?{013}" ;
Print #5 , "AT+DISC?{010}" ;

or catch this proper command from PC with second serial adapter or even uC with LCD how its look in binary.
Back to top
View user's profile Visit poster's website
P_Santos

Bascom Member



Joined: 07 Jul 2011
Posts: 114

PostPosted: Fri Feb 08, 2019 1:22 pm    Post subject: Reply with quote

Hello EDC,

Thank you, but it continue not working

Attached pictures of logic analyser of both, send trough serial adapter and from Atxmega TX pin

The voltage on the serial adapter TX is about 3,26V, on the Atxmega TX pin is about 3,21V

Tested with other terminal programms, send AT+DISC? with 10 or 13 or nothing on the end, the HM11 understand all that

The Usart configuration is
' portE.2/portE.3 - BLE HM11
Config Com5 = 9600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Open "Com5:" For Binary As #5
Config Serialin4 = Buffered , Size = 70

The command from the Atxmega is Print #5, "AT+DISC?"

What is my mistake?

Best regards
P_Santos
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri Feb 08, 2019 1:31 pm    Post subject: Reply with quote

It looks like some baudrate error.
Do you try automatic clock calibration?
After Config clock and Config Sysclock for your config/speed try add last two lines from this example.

Code:
' ***************** SYSTEM CLOCK CONFIG **************************
'                INTERNAL 32MHz NO PRESCALE
'
Config Osc = Disabled , 32mhzosc = Enabled , 32khzosc = Enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
'
' ENABLING AUTOMATIC OSCILLATOR CALIBRATION
    Osc_dfllctrl.0 = 1
     Dfllrc32m_ctrl.0 = 1
 
Back to top
View user's profile Visit poster's website
P_Santos

Bascom Member



Joined: 07 Jul 2011
Posts: 114

PostPosted: Fri Feb 08, 2019 1:51 pm    Post subject: Reply with quote

Sorry, the same result, mention of framming error

Regards
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri Feb 08, 2019 2:06 pm    Post subject: Reply with quote

Better add to topic short but complete code that can be compiled.
Like this but with your settings.
Remember that declared $crystal=xxxxxxxxxx should/must match your Sysclock settings because registers for baudrate are set for clock speed you declare in "$crystal".
If real speed of uC is different then you end with result like yours.

Code:
$regfile = "xm128a3udef.dat"                                'FLASH-128KB,SRAM-8KB,EEP-2KB,7xTIMER,4xDMA,7xUSART,3xSPI,2xTWI,USB
$crystal = 32000000                                         '32MHz
$hwstack = 128                                              'FLASH 10K TIMES
$swstack = 128                                              'EEPROM 100K TIMES
$framesize = 512

' ***************** SYSTEM CLOCK CONFIG **************************
'                INTERNAL 32MHz NO PRESCALE
'
Config Osc = Disabled , 32mhzosc = Enabled , 32khzosc = Enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
'
' ENABLING AUTOMATIC OSCILLATOR CALIBRATION
    Osc_dfllctrl.0 = 1
     Dfllrc32m_ctrl.0 = 1
'*****************************************************************

Config Com5 = 9600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Open "Com5:" For Binary As #5

Print #5 , "AT+DISC?"

End
 


...and every Xmega starts with internal 2MHz so code below should print correctly too (I think).
Code:
$regfile = "xm384C3def.dat"
$crystal = 2000000                                          '2MHz
$hwstack = 128
$swstack = 128
$framesize = 512

Config Com5 = 9600 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Open "Com5:" For Binary As #5

Do
 Print #5 , "AT+DISC?"

 Wait 1
Loop
End
 
Back to top
View user's profile Visit poster's website
P_Santos

Bascom Member



Joined: 07 Jul 2011
Posts: 114

PostPosted: Fri Feb 08, 2019 2:23 pm    Post subject: Reply with quote

Hello IDC,

You are good

Now it works after add 32khzosc = Enabled to my Config Osc = Disabled , 32mhzosc = Enabled

now is: Config Osc = Disabled , 32mhzosc = Enabled , 32khzosc = Enabled

A question, why is Config Osc = Disabled, must it be Enabled

Thank you very much

Best reagards

P_Santos
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri Feb 08, 2019 2:32 pm    Post subject: Reply with quote

Explanation for the question is in Help/Wiki page. Read -> https://wiki.mcselec.com/bavr/CONFIG_OSC
You can always hit F1 in the Bascom code editor if cursor blink near some statements Very Happy

On the mcs main page you can find section Application Notes where one of the topic is 'Statring with Xmegas"

Direct link -> https://www.mcselec.com/index.php?option=com_content&task=view&id=306&Itemid=57

..but is worth to read more of them Wink
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