Level: Resident
Joined: Fri. Nov 29, 2019
Location: India
Posted by Heisen:
Fri. Mar 13, 2020 - 10:38 PM
I trying to read two bits at a time from variables in flash memory.
Using Atmega328p
Example :-
#include <avr/io.h>
#define SBIT(port,pin) ((*(volatile struct bits*)&port).b##pin)
struct bits {
uint8_t b0:2;
uint8_t b1:2;
uint8_t b2:2;
uint8_t b3:2;
} __attribute__((__packed__,__may_alias__));
uint8_t var1 = 0xff;
const __flash uint8_t var2 = 0xff;
uint8_t var3 = 0;
uint8_t var4 = 0;
int main(void)
{
var3 = SBIT(var1,3); // Works
var4 = SBIT(var2,3); // Does not work
while (1)
{
__asm__ __volatile__ ("nop");
}
}
This topic has a solution. Jump to the solution.
“Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?” - Brian W. Kernighan
“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint-Exupery
Tags:
Last Edited: Sat. Mar 14, 2020 - 12:42 AM