Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
while(1){ uart1SendByte('9'); uart2SendByte('9'); delay_ms(200);}
while (true) { cc3_channel_t old_coi; print_prompt (); error = false; if (demo_mode == true) { n = 0; command = TRACK_WINDOW; } else if (raw_mode_input) { n = cmucam2_get_command_raw (&command, arg_list); } else { n = cmucam2_get_command (&command, arg_list); } if (n != -1) { switch (command) {... case LED_0: // The case editted such that the LED will blink int led_blink; // when I type a '9' into the terminal program for (led_blink=0; led_blink<5; led_blink++) // { // cc3_led_set_state (0, true); // cc3_timer_wait_ms (500); // } // if (n != 1 || arg_list[0] > 2) { // error = true; // break; // } // print_ACK (); auto_led = false; if (arg_list[0] == 0) cc3_led_set_state (0, false); if (arg_list[0] == 1) cc3_led_set_state (0, true); if (arg_list[0] == 2) auto_led = true; break;... return 0;}// And below are the functions for getting commands to be input into the switch commandint32_t cmucam2_get_command (cmucam2_command_t * cmd, uint32_t * arg_list){ char line_buf[MAX_LINE]; int c; char *token; bool fail = false; uint32_t length, argc; uint32_t i; length = 0; c = 0; while (c != '\r') { c = getchar (); if (length < (MAX_LINE - 1) && c != EOF) { line_buf[length] = c; length++; } else { // too long or EOF return -1; } } // null terminate line_buf[length] = '\0'; // check for empty command if (line_buf[0] == '\r' || line_buf[0] == '\n') { *cmd = RETURN; return 0; } // start looking for command token = strtok (line_buf, " \r\n"); if (token == NULL) { // no command ? return -1; } // get name of the command for (i = 0; i < strlen (token); i++) { token[i] = toupper (token[i]); } // do lookup of command fail = true; for (i = 0; i < CMUCAM2_CMDS_COUNT; i++) { if (strcmp (token, cmucam2_cmds[i]) == 0) { fail = false; *cmd = i; break; } } if (fail) { return -1; } // now get the arguments argc = 0; while (true) { // extract string from string sequence token = strtok (NULL, " \r\n"); // check if there is nothing else to extract if (token == NULL) { // printf("Tokenizing complete\n"); return argc; } // make sure the argument is fully numeric for (i = 0; i < strlen (token); i++) { if (!isdigit (token[i])) return -1; } // we have a valid token, add it arg_list[argc] = atoi (token); argc++; } return -1;}int32_t cmucam2_get_command_raw (cmucam2_command_t * cmd, uint32_t * arg_list){ bool fail; int c; unsigned int i; uint32_t argc; char cmd_str[3]; cmd_str[2] = '\0'; // read characters for (i = 0; i < 2; i++) { c = getchar (); if (c == EOF) { return -1; } cmd_str[i] = c; } // do lookup of command fail = true; for (i = 0; i < CMUCAM2_CMDS_COUNT; i++) { if (strcmp (cmd_str, cmucam2_cmds[i]) == 0) { fail = false; *cmd = i; break; } } if (fail) { return -1; } // read argc c = getchar (); if (c == EOF) { return -1; } argc = c; if (argc > MAX_ARGS) { return -1; } // read args for (i = 0; i < argc; i++) { c = getchar (); if (c == EOF) { return -1; } arg_list[i] = toupper (c); } // done return argc;}
int data;rprintfInit(uart1SendByte);//output to USBwhile(1) { data=uart3GetByte();//read UART3 if (data!=-1)//check for data rprintf("%c",data);//use %d to output ints }
The CMUCam datasheet says that the cmucam print output is in ASCII format, so there should be nothing wrong with the code. And in any case it works all fine when connected to the PC itself, so my conclusion is that it has to be something in between that is causing the data to corrupt...
data = data & 0x0F; //&0x0F converts ascii to char
int data;rprintfInit(uart1SendByte);//output to USBwhile(1) { data=uart3GetByte();//read UART3 if (data!=-1)//check for data { data = data & 0x0F; //&0x0F converts ascii to char rprintf("%c",data);//use %d to output ints } }
void rprintfChar(unsigned char c){ // do LF -> CR/LF translation //if(c == '\n') //comment out these two lines that cause the LF -> CR/LF // rputchar('\r'); //translation, it will corrupt the JPEG data // send character rputchar(c);}
2. The baud rate for the connection between both items will have to be set to 57600 bps, somehow if you use the default setting of 115200 for the CMUCam3, the 6th data bit will always be mysteriously corrupted (although it works fine with bluetooth modules or RS232 connection to PC).
I suspect this has to do with the error rates. The Axon UART, at 115.2kbps, has a -3.5% error rate. I'm not sure what the error rate on the CMUcam is, but if the error is too far off from the Axon, it'll make sense that it gets corrupted like this.Perhaps try 76.8k?(to know error rates, see page 231 of the ATmega640 datasheet)