Archiv verlassen und diese Seite im Standarddesign anzeigen : SW UART
Hallo RMitglieder,
ich arbeite mit eine mega16 und ich will 2 sw uart implementieren. Ich habe eine auf internet gefunden(http://www.siwawi.arubi.uni-kl.de/avr_projects/softuart_gittins_20050312.zip) und ich habe die Namen doppelt. Der zweite habe ich in Timer O verbinden aber es gibt mir 1 Fehler. Ich habe keine Ahnung ob es arbeitet so ich will Ihre Meinung.
Vielen Dank
Kostas.
SprinterSB
20.12.2006, 00:21
Für den SW-UART braucht man einen Timer als Zeitbasis. Mit Timer0 kann das ohne ANpassungen nicht funktionieren, weil das nur ein 8-Bit-Timer ist, Timer1 jedoch ein 16-Bit-Timer mit zudem anderen Features.
Für 2 UART musst du IMHO neu implementieren und dir genauestens die Timimgs/Bandbreiten überlegen, die du hast bzw willst/brauchst. Im Wiki ist ein Beispiel für einen SW-UART bei den C-Beispielen, vielleicht hilft das je bei einer Tandem-Implementierung?
Vielen Dank!!! Ich versuche etwas tun aber jetzt ich habe eine andere probleme mit ein header...
Entschuldigen Sie mir fuer die Englisch:
In order to implement 2 SW UART in my AVr mega16(3,6864) I have searched and finally found out a solution.
http://www.siwawi.arubi.uni-kl.de/avr_projects
This SW UART needs only a Timer to work and succeed 19200baud rate in 8MHz. Because of my need of 2 SW UART(I know the solution of picking up another avr)I have doubled the numbers of the original names in order to have another one,but this was designed for the avr-gcc and I work with CodeVision. It had given me some errors but I have fixed them. The only one I couldn`t fix and that`s why I am needing your help,if you know of course,is about the headers.
My headers:
#include <mega16.h>
#include <string.h>
#include <stdio.h>
SW headers:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <avr/pgmspace.h>
#include "softuart.h"
My error comes in the last line of my code,in while.
It said that a `)` is missing.
Code:
void softuart_puts( const unsigned char *s )
{
while ( *s ) softuart_putchar( *s++ );
}
void softuart_puts_p( const unsigned char *prg_s )
{
unsigned char c;
while ( ( c = pgm_read_byte( prg_s++ ) ) ) softuart_putchar(c);
}
I found out that pgm_read_byte is a specific expression for the gcc compilerhttp://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html#g73084a8bbde259ffae72980 354b3f027. Can I make it work with some way in CodeVision??
RE:
Change the pointer declaration.
The flash storage modifier can be used in various ways (depending on its relative location within the variable declaration or argument list) to specify what memory space a pointer lives in or points to. Look in your CodeVision help files for details.
Once CodeVision knows the storage type of the memory being pointed-to, the pointer can be dereferenced directly; the pgm_read_byte() macro can be omitted.
Kostas:
void putsf(char flash*str) is ok??
void softuart_putsf( unsigned char *prg_s )
{
unsigned char c;
while ( c = prg_s++ ) softuart_putchar(c);
}
It didn`t gave me an error...but it is correct??
RE:
Are you aware of the fundamental reason there are two different versions of the function? One accepts pointers to strings that reside in Flash (softuart_puts_p), and the other accepts pointers to strings that reside in SRAM (softuart_puts).
The argument list
Code:
void softuart_puts_P(unsigned char flash *prg_s)
...
seems to be correct.
Kostas:
@If morrison thanks!!! I have forgotten flash. In my book Embedded C Programming and the Atmel AVR says :
" The putsf function transmit the contact string str using the standart putchar function, or an alternate putchar function if one has been defined. The string must be null-terminated. A newline character is appended to the end of the string when it is transmitted.Finally the string must be located in FLASH. (see puts for string located in RAM.) The putchar function defaults to transmitting characters using the UART."
And in the SW UART.zip in one file it s said:
"
// Write a NULL-terminated string from RAM to the serial port
void softuart_puts(const unsigned char *s);
// Write a NULL-terminated string from program-space (flash) to the serial port
// i.e. softuart_puts_p(PSTR("test"))
void softuart_puts_p( const unsigned char *prg_s );
// Helper-Macro - "automaticly" inserts PSTR
#define softuart_puts_P(s___) softuart_puts_p(PSTR(s___))"
I don`t know if in CodeVision exists puts_P(My book doesn`t have any reference)!! If it exists why had given me pgm_read_byte false(only in gcc??propably yes!!)?? With the string.h or stdio.h we accept this expression(putsf).
Do you know what is PSTR???
I have tried to do something( with puts or putsf ) but when I omit the pgm_read_byte gives me lots of warnings(10-15) unreferenced function!!!
What can I do????
Tandem-implementierung???
Was ist das?
SprinterSB
20.12.2006, 22:43
The PSTR macro just makes the string residing in flash by adding an attribute.
An ordinary string resides in SRAM to which it is copied by the startup code (from flash). Due to AVRs harvard architecture, one needs a was to specify where the string is located. In avr-gcc, this is done by means of sections. Data in sram belongs to section ".data", whilst data in the flash is contained in section ".progmem" (Code in section ".text" or ".bootloader").
For a string in flash an attribute, namely the section attribute, is used to attach the section. Note that this is just a shortcoming of gcc. The proper was of doing this should be to introduce qualifiers. However, supplying gcc with new qualifiers is *very* painful and error prune...
I am not familiar to CodeVision. Maybe, in that compiler there exists a qualifier for that or some other way. Just browse its manual.
An other way could be to work with virtual addresses. (This is the way binutils copes with harvard).
With tandem implemtation I meant an implementation of 2 SW UARTS that use the same timer. IMHO ATmega8's Timer0 is not very well suited for a SW UART implementation. Using Timer1 for both UARTs is a challenge.
The very problem is to sample the incoming data.
Powered by vBulletin® Version 4.2.5 Copyright ©2024 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.