Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
// Place any #define statements here before you include ANY other files// Now include any other files that are needed here#include "sys/axon2.h" // I am using an Axon#include "uart.h"#include "segled.h"#include "rprintf.h" //Globals int LEDchar = 0; int LEDdec_status = 0; int tchar;void appInitHardware(void){ //code uartInit(UART1, 115200); rprintfInit(&uart1SendByte); //output to UART1 }TICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0; // dont pause after}TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){ //TODO //receive and direct char input from uart int ch = uartGetByte(UART1); if(ch != -1) //if character in ch { tchar = (char)ch; rprintf("%c", ch); rprintfCRLF(); segled_put_char(&led_display, tchar); //send out to onboard LED too } uartFlushReceiveBuffer(UART1); return 200000; // wait for 20ms before calling me again. 1000000 = 1 second}
kdsfdfdseffffsaa...etc.
I actually saw the same thing recently with my SAGAR robot. I forgot to come tell Webbot about it. I fixed the issue by using if (!uartReceiveBufferIsEmpty(uart1))instead of checking against != -1
if (!uartReceiveBufferIsEmpty(UART1))
if (!uartReceiveBufferIsEmpty(uart1)) { temp = uartGetByte(uart1); if(temp == 'X') done = TRUE; // rprintf("%c",temp); //temps[tempi++] = temp; eeprom_write_byte((uint8_t*)tempi++,temp); if (tempi > 2000) { rprintf("Download Error"); done = TRUE; } // delay_us(100); }
I think it may be because you haven't set up any buffers for the UART ie:# define UART1_RX_BUFFER_SIZE 5# define UART1_TX_BUFFER_SIZE 5Hence: 'uartReceiveBufferIsEmpty' always returns true.EDIT: and 'uartFlushReceiveBuffer' will corrupt some memory around address 0 coz the buffer is null (ie 0) - which I will fix so that the call does nothing if there is no buffer
#ifdef UART1_RX_BUFFER_SIZE unsigned char rx1Buf[UART1_RX_BUFFER_SIZE]; cBuffer rx1Buffer = MAKE_BUFFER(rx1Buf);# define rx1B &rx1Buffer#else# define rx1B null#endif
Quote from: Webbot on April 24, 2010, 06:55:39 AMI think it may be because you haven't set up any buffers for the UART ie:# define UART1_RX_BUFFER_SIZE 5# define UART1_TX_BUFFER_SIZE 5Hence: 'uartReceiveBufferIsEmpty' always returns true.EDIT: and 'uartFlushReceiveBuffer' will corrupt some memory around address 0 coz the buffer is null (ie 0) - which I will fix so that the call does nothing if there is no bufferThanks Webbot, but that creates a whole new error!Just adding the two define statements now produces this error on compilation:E:\Robots\LEDNumCounter\..\webbotavrclib\1.17/sys/../dev/ATmega640.h:789: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rx1Buffer'AVRStudio directs me to this block of code in the atmega640.h when I reference (double click the error) the error;Code: [Select]#ifdef UART1_RX_BUFFER_SIZE unsigned char rx1Buf[UART1_RX_BUFFER_SIZE]; cBuffer rx1Buffer = MAKE_BUFFER(rx1Buf);# define rx1B &rx1Buffer#else# define rx1B null#endifIt halts on the 'cBuffer rx1Buffer....' statement.Being new to C and webbotlib, I don't understand what it wants!
Webbot, in my code the buffer was being written to EEPROM, so no terminal software in the mix. When I would dump EEPROM, I would have all these extra spaces as well. Code: [Select]if (!uartReceiveBufferIsEmpty(uart1)) { temp = uartGetByte(uart1); if(temp == 'X') done = TRUE; // rprintf("%c",temp); //temps[tempi++] = temp; eeprom_write_byte((uint8_t*)tempi++,temp); if (tempi > 2000) { rprintf("Download Error"); done = TRUE; } // delay_us(100); }thats my code, except the if used to be if(temp = uartgetbyte(uart1), temp != -1)and this always seemed to return true, after I sent a single character. And my receive buffer was 500 bytes large. ( I know, large. But I wirelessly transfer large mission text files to be stored in EEPROM.)
char temp = 0;
Code: [Select]char temp = 0;Your level of expertise astounds me.I just remember char is unsigned. I'm a fool... :-(
Quote from: madsci1016 on April 24, 2010, 06:11:06 PMCode: [Select]char temp = 0;Your level of expertise astounds me.I just remember char is unsigned. I'm a fool... :-(char is signed. Your problem is probably coming from the fact that it's only 8 bits.You need to declare temp as an int (signed and 16 bits)Chelmi.
Why does it need to be 16 bit? What exactly is it doing?
char temp=0;if(temp = uartgetbyte(uart1), temp != -1){ }
I beg to differ. The C standard default has 'char' as signed (dates back to old 7 bit ascii character values) - but most makefiles, etc, use '-funsigned-char' to tell the compiler to treat chars as unsigned.The '8 bit problem' would only mean that he could not differentiate between receiving a character value of 0xff or 'no data received'
Quote from: Webbot on April 24, 2010, 06:53:33 PMI beg to differ. The C standard default has 'char' as signed (dates back to old 7 bit ascii character values) - but most makefiles, etc, use '-funsigned-char' to tell the compiler to treat chars as unsigned.The '8 bit problem' would only mean that he could not differentiate between receiving a character value of 0xff or 'no data received'Yup, that's in my makefile. So that was my problem.
You need to:#include "buffer.h"
// Place any #define statements here before you include ANY other files#define UART1_RX_BUFFER_SIZE 5#define UART1_TX_BUFFER_SIZE 5// Now include any other files that are needed here#include "sys/axon2.h" // I am using an Axon#include "uart.h"#include "segled.h"#include "rprintf.h"#include "buffer.h" //Globals int LEDchar = 0; int LEDdec_status = 0; int tchar;void appInitHardware(void){ //code uartInit(UART1, 115200); rprintfInit(&uart1SendByte); //output to UART1 }TICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0; // dont pause after}TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){ //TODO //receive and direct char input from uart int ch = -1; ch = uartGetByte(UART1); if(ch != -1 ) //if character in ch { tchar = (char)ch; rprintf("%c", ch); //rprintfCRLF(); segled_put_char(&led_display, tchar); //send out to onboard LED too } //else? uartFlushReceiveBuffer(UART1); return 200000; // wait for 1 second before calling me again. 1000000us = 1 second}
Build started 24.4.2010 at 16:40:39avr-gcc -I"E:\Robots\LEDNumCounter\..\webbotavrclib\1.17" -mmcu=atmega640 -Wall -gdwarf-2 -std=gnu99 -DF_CPU=16000000UL -O0 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT LEDNumCounter.o -MF dep/LEDNumCounter.o.d -c ../LEDNumCounter.cIn file included from E:\Robots\LEDNumCounter\..\webbotavrclib\1.17/sys/../device.h:47, from E:\Robots\LEDNumCounter\..\webbotavrclib\1.17/sys/axon2.h:252, from ../LEDNumCounter.c:8:E:\Robots\LEDNumCounter\..\webbotavrclib\1.17/sys/../dev/ATmega640.h:789: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rx1Buffer'E:\Robots\LEDNumCounter\..\webbotavrclib\1.17/sys/../dev/ATmega640.h:842: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'tx1Buffer'In file included from E:\Robots\LEDNumCounter\..\webbotavrclib\1.17/sys/../device.h:47, from E:\Robots\LEDNumCounter\..\webbotavrclib\1.17/sys/axon2.h:252, from ../LEDNumCounter.c:8:E:\Robots\LEDNumCounter\..\webbotavrclib\1.17/sys/../dev/ATmega640.h:897: error: 'rx1Buffer' undeclared here (not in a function)E:\Robots\LEDNumCounter\..\webbotavrclib\1.17/sys/../dev/ATmega640.h:897: error: 'tx1Buffer' undeclared here (not in a function)make: *** [LEDNumCounter.o] Error 1Build failed with 4 errors and 0 warnings...
Yep - it will work - just adds the overhead of an extra call to test if the uart receive buffer is empty (as uartgetbyte effectively calls it as well!)The code pattern I gave you DOES work - its used all over the lib for serial devices eg gps, blackfin camera etc etc.Its a standard pattern: bit like reading bytes from a file in 'normal C' whereby '-1' indicates the end-of-file
I've also got the Axon flash memory half full. Is that a new record?