ATtiny804 USART

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I begin explore ATtiny804, and wrote a program for USART (from internet):

 

    ldi    r16,low(fBAUD)    ;load low value of fBAUD as calculated in the formula provided above
    ldi    r17,high(fBAUD)    ;load high value of fBAUD as calculated in the formula provided above
    sts    USART0_BAUD,r16    ;store low fBAUD in BAUD register
    sts    USART0_BAUD + 1,r17    ;store low fBAUD in BAUD register
    ldi    r16,USART_TXEN_bm    ;0b01000000 ,(1<<6) ,bitmask value to enable USART transmit
    sts    USART0_CTRLB,r16    ;store TXEN in USART_CTRLB register
    lds    r16,PORTB_DIR
    ori    r16,(1<<2)
    sts    PORTB_DIR,r16    ;set portB PB2 direction as output
    lds    r16,PORTB_OUT
    ori    r16,(1<<2)
    sts    PORTB_OUT,r16    ;set portB PB2 as 1 or +ve

.

.

.

 

serial_out:
    lds    r16,USART0_STATUS    ;copy USART status register to r16
    andi    r16,USART_DREIF_bm     
    sbrs    r16,5        ;skip next instruction if bit 5 is 1
    rjmp    soros        ;if DREIF = 0 ,bit 5 in r16 is 0 then loop back to sendbyte until DREIF = 1
    sts    USART0_TXDATAL,r17    ;store r16 in TXDATAL transmit data low register
    ret

 

 

when I send a caracter, it is invert on TXD pin.

in IDLE state, TXD pin is low!!!

Have an idea any body?

Thx.

 

!!!!!!SOLVED!!!!!

lesson learned :don't stop program (BREAKPOINT) before transmit end!!!!!!!!!!!!!!!!

szinuszkilecven

Last Edited: Thu. Jul 7, 2022 - 10:55 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

why be sloppy ????

 

 sts    PORTB_DIR,r16    

 

PUT SPACES AFTER A COMMA

 

 sts    PORTB_DIR, r16    

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for your attention, but I never put commas there (for 30 years), is has to work without comma.

but already solved the problem. (I was wrong, too early stopped the run, the USART didn't ready yet.)

szinuszkilecven