avr-gcc

accessing AVR registers with C? [closed]

假如想象 提交于 2021-01-29 11:19:38
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago . Improve this question I've been trying to learn everything I can about micro-controllers lately. Since this is self-study, it's taken me a while to learn how the things work at the bare metal. Long story short, I don't want to use the AVR libraries in my C code; I want to access

ATTiny85 - Software UART with Timer1

拜拜、爱过 提交于 2020-12-06 15:47:31
问题 So recently I tried to implement Software UART (TX only) for the ATTiny85. I want to drive it with the internal Timer1. The timer shall interrupt with the frequency of the Baudrate. Every ISR one bit will be transmitted, until there is nothing left to send and the interrupt will be disabled again. (Note: F_CPU=1000000 ; Fuses are the factory default (E:FF, H:DF, L:62) ) #include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> #include <stdint.h> #define SET(reg, pos) (reg |= 1<<

Preprocessor: missing binary operator before token

孤者浪人 提交于 2020-01-07 00:36:28
问题 I'm trying to set up the USART module in an XMEGA micro controller and stumble over an error I can not find. For clarity I give you the complete code. So nothing in this header file is missing. ( F_CPU is defined in the main file) #ifndef USART_H_ #define USART_H_ #include <avr/io.h> #define USART_BAUDRATE 4800 #define USART_BSCALE -3 #if USART_BSCALE < 0 #define USART_BSEL F_CPU / (pow(2,USART_BSCALE) * 16 * USART_BAUDRATE) - 1 #define USART_BAUD_REAL F_CPU / (pow(2,USART_BSCALE) * 16 *

Preprocessor: missing binary operator before token

喜欢而已 提交于 2020-01-07 00:35:10
问题 I'm trying to set up the USART module in an XMEGA micro controller and stumble over an error I can not find. For clarity I give you the complete code. So nothing in this header file is missing. ( F_CPU is defined in the main file) #ifndef USART_H_ #define USART_H_ #include <avr/io.h> #define USART_BAUDRATE 4800 #define USART_BSCALE -3 #if USART_BSCALE < 0 #define USART_BSEL F_CPU / (pow(2,USART_BSCALE) * 16 * USART_BAUDRATE) - 1 #define USART_BAUD_REAL F_CPU / (pow(2,USART_BSCALE) * 16 *

displaying Hexadecimal value in LCD

丶灬走出姿态 提交于 2020-01-06 06:45:32
问题 I wrote LCD interface program for Atmega328 (Though there are libraries available, I wanted to write from scratch). But have two problems. 1. Sometimes LCD does not display correctly. Only few strips are seen. I end up in resetting once or twice. 2. I am unable to display hexadecimal values usingdisplayOneByteHexValue(). However ASCII coversion was correct and I could see that in Atmel Simulator. Below is the code. I am using Atmel Studio 6.2 /* * EmbeddedProgram1.c * * Created: 16-05-2015 08

Does AVR-GCC properly work with 16-bit AVR I/O registers?

做~自己de王妃 提交于 2020-01-05 19:25:35
问题 Preamble It's known that for atomic and simultaneous reading/writing high and low part of 16-bit I/O registers (timer-counters, ICR/OCR, ADC...) AVR uses a shadow temporary register. E.g. reading TCNT1 on ATmega8: uint8_t tl, th; tl = TCNT1L; // tl <- TCNT1L, avr_temp <- TCNT1H (atomic) th = TCNT1H; // th <- avr_temp (Here avr_temp is the AVR temporary shadow register). So, it's wrong to read TCNT1H first, for example. Question Is it safe to use AVR-GCC with the code like the following?

Does AVR-GCC properly work with 16-bit AVR I/O registers?

筅森魡賤 提交于 2020-01-05 19:25:08
问题 Preamble It's known that for atomic and simultaneous reading/writing high and low part of 16-bit I/O registers (timer-counters, ICR/OCR, ADC...) AVR uses a shadow temporary register. E.g. reading TCNT1 on ATmega8: uint8_t tl, th; tl = TCNT1L; // tl <- TCNT1L, avr_temp <- TCNT1H (atomic) th = TCNT1H; // th <- avr_temp (Here avr_temp is the AVR temporary shadow register). So, it's wrong to read TCNT1H first, for example. Question Is it safe to use AVR-GCC with the code like the following?

How to convince avr-gcc, that the memory position of a global byte array is a constant

大城市里の小女人 提交于 2020-01-05 09:14:25
问题 I writing a fast " 8 bit reverse "-routine for an avr-project with an ATmega2560 processor. I'm using GNU C (WinAVR 20100110) version 4.3.3 (avr) / compiled by GNU C version 3.4.5 (mingw-vista special r3), GMP version 4.2.3, MPFR version 2.4.1. First I created a global lookup-table of reversed bytes (size: 0x100): uint8_t BitReverseTable[] __attribute__((__progmem__, aligned(0x100))) = { 0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0, 0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0, [...] 0x1F,0x9F,0x5F

cast unsigned char * (uint8_t *) to const char *

孤街浪徒 提交于 2020-01-02 06:15:09
问题 I've a function which take an uint8_t * argument : uint8_t* ihex_decode(uint8_t *in, size_t len, uint8_t *out) { uint8_t i, hn, ln; for (i = 0; i < len; i+=2) { hn = in[i] > '9' ? (in[i]|32) - 'a' + 10 : in[i] - '0'; ln = in[i+1] > '9' ? (in[i+1]|32) - 'a' + 10 : in[i+1] - '0'; out[i/2] = (hn << 4 ) | ln; } return out; } I use this function with : uint8_t data[SPM_PAGESIZE]; // SPM_PAGESIZE = 256 bytes uint8_t sysex_data[SPM_PAGESIZE/2]; ihex_decode(data, strlen(data), sysex_data); But in

-gc-sections discards used data

让人想犯罪 __ 提交于 2020-01-01 11:45:17
问题 Using avr-gcc, avr-ld I'm attempting to severely reduce the size of the output file by using fdata-sections -ffunction-sections and gc-sections. When compiled without these options I have an output of ~63KB, and with these options its ~30KB, so it seems great. Unfortunately, after loading and testing the output I notice it doesn't work correctly. Garbage collection seems to have removed far more than I expected, and examining the .map I notice some key data is nonexistent. Any idea on what at