Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Atmega 328p How reset by software ?

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

Bascom Member



Joined: 24 Feb 2019
Posts: 10
Location: Rio de Janeiro

brazil.gif
PostPosted: Thu Jun 06, 2019 4:02 am    Post subject: Atmega 328p How reset by software ? Reply with quote

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
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1119
Location: SYDNEY

australia.gif
PostPosted: Thu Jun 06, 2019 5:02 am    Post subject: Reply with quote

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
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 607

poland.gif
PostPosted: Thu Jun 06, 2019 7:35 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 865
Location: France

france.gif
PostPosted: Thu Jun 06, 2019 9:01 am    Post subject: Reply with quote

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 Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4798
Location: Holland

blank.gif
PostPosted: Thu Jun 06, 2019 11:51 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
aphawk

Bascom Member



Joined: 23 Jan 2010
Posts: 152
Location: Brazil

brazil.gif
PostPosted: Fri Jun 07, 2019 10:53 pm    Post subject: Reply with quote

acjacques,

Hi my friend, I wrote one tutorial with many examples in Bascom to newbies, here in Brazil :

https://www.clubedohardware.com.br/forums/topic/937085-projetos-com-avr-design-programa%C3%A7%C3%A3o-em-basic-e-assembly/

You can download my tutorial with more than 150 pages, with Proteus simulations too, in Portuguese language.

Paulo
Back to top
View user's profile
acjacques

Bascom Member



Joined: 24 Feb 2019
Posts: 10
Location: Rio de Janeiro

brazil.gif
PostPosted: Sat Jun 08, 2019 10:57 pm    Post subject: Reply with quote

aphawk wrote:
acjacques,

Hi my friend, I wrote one tutorial with many examples in Bascom to newbies, here in Brazil :

https://www.clubedohardware.com.br/forums/topic/937085-projetos-com-avr-design-programa%C3%A7%C3%A3o-em-basic-e-assembly/

You can download my tutorial with more than 150 pages, with Proteus simulations too, in Portuguese language.

Paulo


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
View user's profile
acjacques

Bascom Member



Joined: 24 Feb 2019
Posts: 10
Location: Rio de Janeiro

brazil.gif
PostPosted: Thu Jun 20, 2019 8:56 pm    Post subject: Reply with quote

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
View user's profile
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