|
From: | Wouter van Gulik |
Subject: | Re: [avr-gcc-list] avr-gcc and char strings |
Date: | Wed, 3 Dec 2014 22:21:42 +0100 |
Could you post the assembler output? IIRC --save-temps or -S should be added to the gcc command line.
Wouter
Hi all,I am close to tearing my hair out. After having established the avr tool chain I tried out a very simple C-program (see below) on an SainSmart Mega2560 board programmed into the chip by making use of /Applications/Arduino.app//Contents/Resources/Java/hardware/tools/avr/bin/avrdude:#define F_CPU 16000000UL /* 16 MHz CPU clock */#include "Global.h"#include <util/delay.h>#include <avr/io.h>#include <avr/interrupt.h>#include <inttypes.h>
char String[] = "Hello world!!";
void USARTInit0(uint16_t baud){// Set Baud rateint value = (F_CPU / 16 / baud) - 1;UBRR0H = (uint8_t)(value>>8);UBRR0L = (uint8_t)value;
// 8N1UCSR0C = 0x06; // (3<<UCSZ00);
// Enable receiver and transmitterUCSR0B = (1<<RXEN0) | (1<<TXEN0);}
void TxByte0 (uint8_t data){// Wait for empty transmit bufferwhile ( !(UCSR0A & (1 << UDRE0)) );// Putting data into the buffer, forces transmissionUDR0 = data;}
int main (void){DDRB = 0xff; // all outputs
USARTInit0(38400); // 9600 19200 38400
while (1){TxByte0('A');TxByte0('B');TxByte0('C');TxByte0('\n');
char *s = String;while (*s != 0){TxByte0(*s);s++;}
_delay_ms(500);}return (0);}
This program produces the following output...ÿÿÿÿÿÿÿÿÿÿÿÿÿÿABCÿÿÿÿÿÿÿÿÿÿÿÿÿÿABCÿÿÿÿÿÿÿÿÿÿÿÿÿÿABC...
telling me that sending single chars works but sending strings fails (does not seem to have anything to do with the serial communication but rather be some kind of memory management problem!??).
To be sure the problem is not caused by my own gcc build I changed my Makefile to
# AVR-GCC MakefilePROJECT=toggle_ledSOURCES=main.cHEADERS=CC=/Applications/Arduino.app//Contents/Resources/Java/hardware/tools/avr/bin/avr-gccOBJCOPY=avr-objcopyMMCU=atmega2560
CFLAGS=-mmcu=$(MMCU) -Wall -O2 -I /usr/local/avr/include$(PROJECT).hex: $(PROJECT).out$(OBJCOPY) -j .text -O ihex $(PROJECT).out $(PROJECT).hex
$(PROJECT).out: $(SOURCES)$(CC) $(CFLAGS) -I./ -o $(PROJECT).out $(SOURCES)
program: $(PROJECT).hexavrdude -p $(MMCU) -c avrispmkII -P usb -e -U flash:w:$(PROJECT).hexclean:rm -f $(PROJECT).outrm -f $(PROJECT).hex
and thus built the program with a gcc from a respected source (avr-gcc coming with Arduino.app). But the problem persists!? I already discussed this problem on avrfreaks forum. All agree that the above code should work but it does not!?? :-()Could this be a problem of the board/chip? I am using a SainSmart Mega2560 board (which seems to be a clone of the original Arduino product)! Or am I doing anything wrong??
Clueless!?? :-( Hints are greatly appreciated!!
Thanks a lot,
Andreas
_______________________________________________
AVR-GCC-list mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
[Prev in Thread] | Current Thread | [Next in Thread] |