Split from: ATtiny417 / ATtiny814 / ATtiny816 / ATtiny817

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

Platform Xplained mini Attinny817 - i cant send "f" to windows terminal  i use virtual port.

 

#define F_CPU 20000000UL
#define BAUDRATE 115200UL
#define CALC_BAUD  ((64 * F_CPU + 8 * BAUDRATE) / (16 * BAUDRATE))

#include <stdio.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>

	void USART_SEND(char data2);
	void USART_Init(uint16_t baud);

int main(void)

{
(CLKCTRL_MCLKCTRLB, 0);

	PORTB.OUTSET = PIN2_bm;  //uart pin
	PORTB.DIRSET = PIN2_bm;
	sei();
	USART_Init(CALC_BAUD);  

	PORTC.DIRSET = PIN0_bm;  //led board
	PORTC.OUTSET = PIN0_bm;

    while (1)
    {
		PORTC.OUTTGL = PIN0_bm;  //LED

		USART_SEND('H');
		USART_SEND('A');
		USART_SEND('L');
		USART_SEND('L');
		USART_SEND('O');
		USART_SEND('\n');

		_delay_ms(100);
	}
}

//********************************************************
//********************************************************
void USART_SEND(char data2)
{
	while ((USART0.STATUS  & USART_DREIF_bm)==0); 

	USART0.TXDATAL=data2;

}

void USART_Init(uint16_t baud)
{
	USART0.BAUDH = (uint8_t)(baud>>8);
	USART0.BAUDL = (uint8_t)baud;

	USART0.CTRLB = USART_TXEN_bm;
	USART0.CTRLC = USART_CHSIZE_8BIT_gc;
}

 

This topic has a solution.
Last Edited: Wed. Apr 26, 2017 - 08:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ross McKenzie ValuSoft Melbourne Australia

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

Why are the lines for setting the baud rate commented out? 

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

I changed code,works OK now, but i use in the program BAUDRATE speed 115200.The trminal windows 19200!. :(

I think I'm have wrong setting clock frequency Atmel Studio7.This is my first time with Atmel Studio :(

 

edit:OK,i must OFF prescaler.

edit2.Anyone know how to set zero in the registry? CLKCTRL.MCLKCTRLB= !(CLKCTRL_PEN_bm);

Last Edited: Tue. Apr 25, 2017 - 12:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

_PROTECTED_WRITE(CLKCTRL_MCLKCTRLB, !(CLKCTRL_PEN_bm));      // OFF prescaler.

 

It works ! a magic word is required   ''_PROTECTED_WRITE"   laugh

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You were attempting to alter a register that is protected by the Configuration Change Protection (CCP) mechanism, but you weren't disabling the protection.   _PROTECTED_WRITE() is a macro that expands to inline assembly code that disables this protection for you (for 4 clock cycles - read about CCP).

 

 

edit; CPP -> CCP

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

Last Edited: Tue. Apr 25, 2017 - 10:10 PM