Author Topic: ATmega4809 won't respond  (Read 1814 times)

0 Members and 1 Guest are viewing this topic.

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18908
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
ATmega4809 won't respond
« on: July 10, 2019, 10:19:06 am »
I wrote a program for a project with an atmega3208 an got absolutely nothing out. So I started to play with the dev board with a 4809 on it. I wrote the below simplest of programs but other than clock out I get nothing other that some pins permanently low or high:

Code: [Select]
int main(void)
{

CCP = 0xD8;
CLKCTRL.MCLKCTRLA = 0b10000000;
PORTA.DIRSET = 0xFF;
PORTB.DIRSET = 0xFF;
PORTC.DIRSET = 0xFF;
PORTD.DIRSET = 0xFF;
PORTE.DIRSET = 0xFF;
PORTF.DIRSET = 0xFF;


while(1){
PORTA.OUTSET = 0xFF;
PORTB.OUTSET = 0xFF;
PORTC.OUTSET = 0xFF;
PORTD.OUTSET = 0xFF;
PORTE.OUTSET = 0xFF;
PORTF.OUTSET = 0xFF;

PORTA.OUTCLR = 0xFF; 
PORTB.OUTCLR = 0xFF;
PORTC.OUTCLR = 0xFF;
PORTD.OUTCLR = 0xFF;
PORTE.OUTCLR = 0xFF;
PORTF.OUTCLR = 0xFF;
}

}
« Last Edit: July 10, 2019, 10:51:53 am by Simon »
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18908
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: ATmega4809 won't respond
« Reply #1 on: July 10, 2019, 10:54:55 am »
now working, I did nothing, very strange.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4660
  • Country: us
Re: ATmega4809 won't respond
« Reply #2 on: July 10, 2019, 11:25:57 pm »
I have (using MPLAB-X):
Code: [Select]
#define F_CPU (20000000/6)
 #include <xc.h>
 #include <util/delay.h>

void  __attribute__((noinline)) mydelay();
void mydelay() {
   _delay_ms(1000);
}

void main(void) {
    VPORTA.DIR |= 1<<7;
    while (1) {
        mydelay();
        VPORTA.IN |= 1<<7;
    }
    return;
}

Which works fine, even on my home-built hardware...
 

Offline cv007

  • Super Contributor
  • ***
  • Posts: 1061
Re: ATmega4809 won't respond
« Reply #3 on: July 11, 2019, 12:47:53 am »
VPORTA.IN |= 1<<7;

Looked odd to me.
I totally missed that in the datasheet (even though I know I read it).
Glad you posted that code :)

datasheet-
Writing to a bit of VPORTx.IN will toggle the corresponding bit in VPORTx.OUT.
There is the missing VPORT TGL.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4660
  • Country: us
Re: ATmega4809 won't respond
« Reply #4 on: July 11, 2019, 03:17:46 am »
Quote
Writing to a bit of VPORTx.IN will toggle the corresponding bit in VPORTx.OUT.
The VPORT registers (DIR, OUT, IN) are essentially compatible with the DDR/PORT/PIN registers of the older ATmega chips.  (A good move on their part, IMO.)  (Writing 1 to the PINx register of an ATmega328 (for example) will also toggle the output.  "very old" ATmega chips (like ATmega8) do not have this feature.)
 

Offline cv007

  • Super Contributor
  • ***
  • Posts: 1061
Re: ATmega4809 won't respond
« Reply #5 on: July 11, 2019, 05:05:45 am »
I was using OUTTGL for my tog() function, as I somehow equated no TGL register in VPORT to mean in wasn't there. I haven't touched an avr in a long time (mega88/168/etc), but do remember the PIN toggle.

https://github.com/cv007/ATTiny416XplainedNano/blob/master/Port.hpp

Now I feel better as it matches the rest of the pin functions, and I can save a few bytes every time I toggle an led (seems to be the only time I use toggle).

For really nice bit setting/clearing, the pic32 (I use the mm) is nice to use where almost every register is capable of set/clr/inv (every register is 32bits, and there are 4 for each).

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->