Good day all,
I am having an issue that I don't understand. As part of my simple state machine I have a help if you press h, but if this help information gets too big the text becomes truncated and corrupted, not only of help, but most other outputs to usart, in the extreme case the thing just fails to run.
What am I doing wrong? (in relation to this question 9)
Hope this is the right forum and I given enough code:
usart.c: /* usart enable send/recv mode: 8N1 @ 57600 */ void init_usart() { UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0); UCSR0C = (1 << UCSZ00) | (1 << UCSZ01); UBRR0 = F_CPU / 16 / BAUDE_RATE - 1; } /* write a single byte to the usart */ void send_char(uint8_t byte) { while (~UCSR0A & (1 << UDRE0)); UDR0 = byte; } /* write a null-terminated string to the usart */ void send_string(const char *s) { while (*s) { send_char(*s++); } } void send_newline() { send_char('\r'); send_char('\n'); }
and
command.c: void handle_line(const char* line) { char *endptr = 0; //Check whether rest of line is a number and if so proceed to logic uint32_t argument_value = strtoul(line+1, &endptr, 10); if (*endptr == '\0') { command_from_serial(line[0], argument_value, &program); } } /* The Giant mess that is the commands from serial */ void command_from_serial(char commandname, uint32_t commandvalue, struct Program *program) { struct Inputs *inputs = &program->inputs; struct Settings *settings = &program->settings; switch(commandname) { //Help! case 'h': //Disable logging // send_string("Help! Available commands."); send_newline(); send_string("Commands are case sensetive letters followed by a number (commandvalue) with no space"); send_newline(); send_string("Default commandvalue is 0 if not given"); send_newline(); send_char('\t'); send_string("L: X "); send_char('\t'); send_char('\t'); send_string("S: X "); send_char('\t'); send_char('\t'); send_string("F: X "); send_char('\t'); send_char('\t'); send_string("H: X "); send_newline(); send_char('\t'); send_string("P: X "); send_char('\t'); send_char('\t'); send_string("f: X "); send_char('\t'); send_char('\t'); send_string("b: X "); send_char('\t'); send_char('\t'); send_string("t: X "); send_newline(); send_char('\t'); send_string("T: X "); send_char('\t'); send_char('\t'); send_string("Y: X "); send_char('\t'); send_char('\t'); send_string("y: X "); send_char('\t'); send_char('\t'); send_string("U: X "); send_newline(); send_char('\t'); send_string("u: X "); send_char('\t'); send_char('\t'); send_string("M: X "); send_char('\t'); send_char('\t'); send_string("m: X "); send_char('\t'); send_char('\t'); send_string("J: X "); send_newline(); send_char('\t'); send_string("N: X "); send_char('\t'); send_char('\t'); send_string("n: X "); send_char('\t'); send_char('\t'); send_string("G: X "); send_char('\t'); send_char('\t'); send_string("g: X "); send_newline(); send_char('\t'); send_string("s: X "); send_char('\t'); send_char('\t'); send_string("d: X "); send_char('\t'); send_char('\t'); send_string("C: X "); send_char('\t'); send_char('\t'); send_string("O: X "); send_newline(); send_char('\t'); send_string("o: X "); send_newline(); break;
THis is the short version that mostly works, any more text in place of the X's causes corruption on USAART output and ine the extreeme lockup of the device. The case statement is veeeery long with so many damn options!
main.c: //USART while (num_in_serial_buffer()) { //check whether there is anything on the serial buffer, if there is, look at it handle_single_char_from_serial(); }
OMG what can I do please oh gurus?