View previous topic :: View next topic |
Author |
Message |
acjacques
Joined: 24 Feb 2019 Posts: 13 Location: Rio de Janeiro
|
Posted: Thu Jun 06, 2019 4:02 am Post subject: Atmega 328p How reset by software ? |
|
|
Hi friends;
I am newbie in the AVR world... (coming from PicBasic Pro...)
Did someone have a code that could reset the ATmega 328p by software ?
Thanks for any help
(BASCOM-AVR version : 2.0.8.1 ) |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Thu Jun 06, 2019 5:02 am Post subject: |
|
|
Hello acjacques
I use this to go to the boot vector via a serial port
so I can load new code into the M168 over RS232
if I get 123 sent to the serial port it jumps to the boot vector
Note bascom boot loader sends 123
so this lets me program the M168 remotely without pressing the reset
Regards Paul
Code: |
Config Serialin0 = Buffered , Size = 20 , Bytematch = 123
Serial0charmatch:
Cls
Lcd "BOOT VECTOR"
Wait 1
'here you need to read the data sheet
'to find the correct address
Goto &HC00
Return
|
|
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Thu Jun 06, 2019 7:35 am Post subject: |
|
|
Here you have. Now you can add more "AT" commands but this basic code react for "AT+RST".
You can use it for debug/reseting over Bascom,or any other, terminal emulator , or even use it with MCS Bootloader.
Code: | $regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 64
$swstack = 16
$framesize = 64
$baud = 115200
Const Buffs_len = 50
'*****************************************************************
'* CONFIG BUFFERED USART FOR DEBUG via USB *
'*****************************************************************
Config Serialin0 = Buffered , Size = Buffs_len 'RX from Terminal
Dim Char As Byte , Cmd_timeout1 As Byte , Got_str As Byte
Dim Command1 As String * Buffs_len
Open "COM1:" For Binary As #1
Const Usb = 1
'*****************************************************************
'* TIMER2 FOR TIME BASE *
'*****************************************************************
Config Timer2 = Timer , Prescale = 1024 , Clear_timer = 1
Compare2a = 155 '10ms @16MHz/1024
'*****************************************************************
'* VARIABLES *
'*****************************************************************
'general purposes
Dim Tempb As Byte
' ----------------------------
'| PROGRAM START |
' ----------------------------
Enable Interrupts ' for serial receiving in the background interrupt
Do
'--[ USART0 COM1 USB ]------------------------
If 0 < Ischarwaiting(#usb) Then
Char = Inkey(#usb)
Select Case Char
Case 10 : Got_str = 1
Case 13 : 'swallow
Case Else
Command1 = Command1 + Chr(char)
End Select
If Len(command1) > 49 Then Got_str = 1 'force parsing
If Got_str = 0 Then Cmd_timeout1 = 50 '50x10ms
'end if Ischarwaiting
End If
'--[ PARSE COM1 USB ]-------------------------
If Got_str = 1 Then
'-------------------------------------
Tempb = Instr(command1 , "AT+RST")
If Tempb > 0 Then
Print #usb , "Reseting in progress..."
Disable Interrupts
Config Watchdog = 16 'set shortest time
Start Watchdog 'always strt WD after config
Do : Loop 'wait for reset in neverending loop
End If
'-------------------------------------
Got_str = 0
Command1 = ""
Cmd_timeout1 = 0
End If
'--[ TIMER2 10ms ]----------------------------
If Tifr2.ocf2a = 1 Then
Tifr2.ocf2a = 1
'COM1 USB
If Cmd_timeout1 > 0 Then
Decr Cmd_timeout1
If Cmd_timeout1 = 0 Then
'Got_str = 1 'force parsing
Command1 = "" 'or clear trash
End If
End If
End If
Loop
End |
|
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Thu Jun 06, 2019 9:01 am Post subject: |
|
|
When I want to restart a prog , I use goto 0
look at the help
"Besides using a label you can also specify an address. GOTO &H0000 would jump to the reset vector of the processor. "
JP _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Thu Jun 06, 2019 11:51 am Post subject: |
|
|
A GOTO 0 or GOTO _RESET is a soft reset. It will just start the code from the start. It will not put the hardware registers in their default.
Using the watchdog like EDC demonstrates is a hard internal reset. This does reset the hardware registers too. _________________ Mark |
|
Back to top |
|
|
aphawk
Joined: 23 Jan 2010 Posts: 168 Location: Brazil
|
|
Back to top |
|
|
acjacques
Joined: 24 Feb 2019 Posts: 13 Location: Rio de Janeiro
|
Posted: Sat Jun 08, 2019 10:57 pm Post subject: |
|
|
Prezado Antonio Paulo Hawk;
Obrigado pelo tutorial. Bem interessante e útil.
Tenho alguma experiencia prévia em PICBasic Pro. Estou usando placas Arduino Nano que săo bem praticas por incluir o conversor USB e poder programar com Bootloader.
ACJacques |
|
Back to top |
|
|
acjacques
Joined: 24 Feb 2019 Posts: 13 Location: Rio de Janeiro
|
Posted: Thu Jun 20, 2019 8:56 pm Post subject: |
|
|
Dear friends;
Using
if resetcommand = 1 then
Wdtcsr = &B11111111
endif
in my code it do a reset in about 2 seconds, but it will not start again unless repowering the device.
I have wrote
Wdtcsr = 0
in the begining of my code but it seems not work
Have I miss some code ?
I am using a bootloader
Atmega328p |
|
Back to top |
|
|
|