avr

Linking AVR programs with Cargo

懵懂的女人 提交于 2020-01-17 07:18:22
问题 I have a Rust project which I am currently compiling and linking by hand: rustc --target=avr-atmel-none src/main.rs --emit=obj -o _build/main.rs.o -C opt-level=3 avr-gcc -Os -Wl,--gc-sections -mmcu=atmega328p -o _build/image.elf _build/main.rs.o avr-objcopy -Oihex -R.eeprom _build/image.elf _build/image.hex I would like to automate this with Cargo, so I started by setting avr-gcc as the linker, by adding the following to .cargo/config : [build] target = "avr-atmel-none" [target.avr-atmel-none

Serial communication between pc and Arduino through USB

浪尽此生 提交于 2020-01-16 08:42:01
问题 I have some C++ code that I need to use for serial communication between PC and Arduino. The file "Serial.cpp" is including a file called "stdafx.h" that doesn't exist in the project or anywhere on my computer, which obviously causes an error. Other than that, I also get other errors, such as C2065 'CSerial': undeclared identifier . Here are the three files that are in the project: Serial.h #ifndef __SERIAL_H__ #define __SERIAL_H__ #pragma once #include <Windows.h> #include <memory.h> #define

Serial communication between pc and Arduino through USB

自作多情 提交于 2020-01-16 08:40:11
问题 I have some C++ code that I need to use for serial communication between PC and Arduino. The file "Serial.cpp" is including a file called "stdafx.h" that doesn't exist in the project or anywhere on my computer, which obviously causes an error. Other than that, I also get other errors, such as C2065 'CSerial': undeclared identifier . Here are the three files that are in the project: Serial.h #ifndef __SERIAL_H__ #define __SERIAL_H__ #pragma once #include <Windows.h> #include <memory.h> #define

AVR I2C trouble

僤鯓⒐⒋嵵緔 提交于 2020-01-16 08:35:31
问题 I am trying to communicate using I2C with AT90CAN128, But it is not going further than following while loop: while(!(TWCR & (1<<TWINT))); It remains in the while loop. According to me, it is not able to set TWINT flag. void TWI_start(void) { TWCR= (1<<TWINT)|(1<<TWSTA)|(1<<TWEN); while(!(TWCR & (1<<TWINT)));`enter code here` while((TWSR & 0xF8)!= 0x08); } Any suggestions? 回答1: Probably a hardware problem. The TWI Master tries to assert SDA and SCL and checks if both SDA and SCL are at GND.

Finding position of '1's efficiently in an bit array

十年热恋 提交于 2020-01-14 09:48:27
问题 I'm wiring a program that tests a set of wires for open or short circuits. The program, which runs on an AVR, drives a test vector (a walking '1') onto the wires and receives the result back. It compares this resultant vector with the expected data which is already stored on an SD Card or external EEPROM. Here's an example, assume we have a set of 8 wires all of which are straight through i.e. they have no junctions. So if we drive 0b00000010 we should receive 0b00000010. Suppose we receive

Calculator Based on ATMega8 using AVRstudi

十年热恋 提交于 2020-01-07 08:32:29
问题 About the Calculator: Basically this calculator is made to calculate the resistance of copper and aluminum wires at the ambient temperature using the formula R2= R1*(1+alpha(T-25)) Here R2 will be the output, R1 will be the value entered by the user using a 4x4 matrix keypad (which will include decimal values like 12.5 etc), T is the temperature in degree Celsius recorded by the temperature sensor LM35. alpha for copper = 0.0039 alpha for aluminum = 0.0042 How it should work: Basically the

avr gcc inline asm variable input operand

有些话、适合烂在心里 提交于 2020-01-06 04:55:07
问题 I want to be able to determine the port register for an inline asm function at runtime asm(""::"I" (_SFR_IO_ADDR(PORTD))); _SFR_IO_ADDR only accepts a constant I have found these options but can't seem to pass register from variable. asm(""::"m" (PORTD)); asm(""::"n" (&PORTD)); Thought this would be a common issue/request but can't seem to find any answers 回答1: The AVR IN instruction only supports immediate port number. You might want to try memory mapped access instead, if available. –

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?

Why doesn't this compiler barrier enforce ordering?

天涯浪子 提交于 2020-01-02 07:54:07
问题 I was looking at the documentation on the Atmel website and I came across this example where they explain some issues with reordering. Here's the example code: #define cli() __asm volatile( "cli" ::: "memory" ) #define sei() __asm volatile( "sei" ::: "memory" ) unsigned int ivar; void test2( unsigned int val ) { val = 65535U / val; cli(); ivar = val; sei(); } In this example, they're implementing a critical region-like mechanism. The cli instruction disables interrupts and the sei instruction