855 questions
1
vote
2
answers
182
views
Why we use PIN & (1<<PBx) to check if PIN is high?
I'm a beginner working on AVR programming on the ATmega328P. I am trying to get input from a button and then control an LED.
void setup() {
DDRB |= (1<<PB5);
DDRB &= ~(1<<PB4);
...
0
votes
1
answer
65
views
“avrdude: verification error; content mismatch” error when programming AVR based microcontrollers
When programming for an AVR compatible micro controller, such as the Atmega328p, you're facing an error after successfully building and uploading a first time, but all subsequent times result in an ...
0
votes
0
answers
56
views
yl-69 sensor - adc conversion does not change adch and adcl - avr assembly
The YL-69 sensor(for soil moisture using a comparator circuit LM-393) is functional. When tested with C code on the Arduino IDE, it prints the correct values on the serial monitor. However, when ...
-3
votes
2
answers
125
views
AVR-GCC macro behaviour
I have a simple C program:
#include <stdint.h>
#define WHEELS_PWM_CYCLES_PER_MS (5)
#define WHEELS_TIME_TO_GO_1_CM_MS (10)
int main(void)
{
for (;;) {
uint32_t x = (uint32_t)...
1
vote
0
answers
96
views
Simavr - ATmega328P timer flags behaving oddly
I am using Simavr to simulate an AVR ATmega328P chip, so I dont know if this is a problem in the simulation or if it happens in the MCU too.
When using the timer0 in CTC mode the TOV0 flag seems to be ...
0
votes
1
answer
90
views
AVR Embedded question (rstack and cstack)
I have a project in college where the main in asm has to call a function in c, but I don't know how to initialize the stack (rstack and cstack). I mention that the project is on an atmega16.
Main asm ...
0
votes
0
answers
263
views
Implementing SPI with Rust and QEMU
For learning purposes, I am trying to build my own HAL in Rust for the Atmega328P.
Context
So far, I managed the USART part. I created a code that sends back via USART the data it receives, and ...
0
votes
1
answer
37
views
Simulating T0 external clock for Timer0 on Microchip Studio with ATmega328p
I've setup Timer0 to work with an external clock on pin T0:
TCCR0A=0x02 // CTC Mode
TCCR0B=0x07 // Start timer on external T0 clock (rising edge)
OCR0A=90 // Compare after 90 clock ticks
TIMSK0=0x03 //...
0
votes
1
answer
90
views
What is wrong with this C code to control a LED using a sensor and a push button?
I am trying to program an ATmega328P to control an LED using an HC-SR04 sensor and a push button. My goal is for the sensor to turn ON the LED (like turn on a light in a room) when something passes ...
1
vote
1
answer
77
views
avr-gcc ATmega4809 problem with `.rodata` section
(This is a follow up of this question)
The following program doesn't work (in ATmega4809)
#include <avr/io.h>
void f(const char str[])
{
if (str[0] == 'a') // <-- here is the problem. ...
3
votes
1
answer
95
views
Problem with avr-g++ 13.3.0 passing const char array as parameter in ATmega4809 (40 pins)
The following code doesn't work in ATmega4809:
#include <avr/io.h>
#include <util/delay.h>
void f(const char str[])
{
if (str[0] == 'a'){ // <-- here is the problem!!! The program ...
-2
votes
1
answer
81
views
My Arduino code stops working when i try to manipulate the ports instead of using pinMode() and digitalWrite()
The uncommented code works perfectly fine, but as you can see i have commented all the port related lines which i think should do the equivalent as the uncommented ones, but when i uncomment those and ...
1
vote
0
answers
85
views
Why isn't the 0 on my keypad being recognised?
I was trying to finish my project using an physical OUSB-IO board on a ATmega32A board using Microchip Studio's C to create a stopwatch and timer on the same LED board to indicate that it's working. ...
3
votes
1
answer
640
views
ATmega328P hex file, reverse engineering and debugging
I have a compiled hex file for the ATmega328P microcontroller, but no source code. I need to find a way to debug this in the AVR simulator.
What I already did:
Installed Microchip Studio, which has ...
0
votes
1
answer
92
views
Compiler Truncates Interrupts Vectors of ATmega328PB in Eclipse AVR Plugin
I would normally use Eclipse avr-gcc plugin and (avr-gcc compiler from zaks https://blog.zakkemble.net/avr-gcc-builds) to develop firmware for AVR MCU.
The MCU ATmega328PB has extra timers (3,4), SPI1,...