how I might do this, I've been writing programs that just send BT messages, then display the results. Some
messages are the sum of hex values, and these messages were arriving incomplete. Displaying the sum on the
sending NXT, before sending, I found the incomplete messages. To debug this, I wrote some smaller simpler
programs. If seems that if my program uses (sends, displays) the sum of several hex digits too soon after the
addition, the value is incomplete. (Although, I haven't totally ruled out my typing, my code, or ????) I tried this
on 2 different NXTs, with same results. Any suggestions are appreciated. My test program below has 6 different
examples that I've tried. Trials 0 and 1 are probably the simplest "FAILS" , "WORKS" examples. Does that fact
that I'm using #defines matter? The problem seems to be worse as the battery wears down, but I haven't done
enough tests to confirm this.
Thanks. Howard
Code: Select all
// File hex_addition_test_02.nxc
// Created by: hdrake, TabbyCat Robots 2012Feb13
#define ACK_STUB 0xc0000000
#define I_NEED 0x00310000
#define BUTTON_PRESS_DELAY 700
task main()
{
unsigned long msg_to_send;
unsigned long data_digits;
unsigned char rcvd_msg_id;
unsigned char poll_cntr_A;
rcvd_msg_id = 1;
/****************** Trial 0 - Base - Fails ********************************/
msg_to_send = ACK_STUB + rcvd_msg_id;
ClearLine(LCD_LINE2);
TextOut(0, LCD_LINE2, "Trial 0 Fails");
ClearLine(LCD_LINE6);
TextOut(0, LCD_LINE6, FormatNum("ACKm 0x%x", msg_to_send));
TextOut(0, LCD_LINE8, "Push BTNctr");
until(ButtonPressed(BTNCENTER, TRUE));
Wait(BUTTON_PRESS_DELAY);
ClearLine(LCD_LINE8);
/****************** Trial 1 - Wait - Works ********************************/
msg_to_send = ACK_STUB + rcvd_msg_id;
Wait(500); // Works
ClearLine(LCD_LINE2);
TextOut(0, LCD_LINE2, "Trial 1 Works");
ClearLine(LCD_LINE6);
TextOut(0, LCD_LINE6, FormatNum("ACKm 0x%x", msg_to_send));
TextOut(0, LCD_LINE8, "Push BTNctr");
until(ButtonPressed(BTNCENTER, TRUE));
Wait(BUTTON_PRESS_DELAY);
ClearLine(LCD_LINE8);
/****************** Trial 2 - Fails *****************************************/
msg_to_send = ACK_STUB + I_NEED + rcvd_msg_id; // Fails
ClearLine(LCD_LINE2);
TextOut(0, LCD_LINE2, "Trial 2 Fails");
ClearLine(LCD_LINE6);
TextOut(0, LCD_LINE6, FormatNum("ACKm 0x%x", msg_to_send));
TextOut(0, LCD_LINE8, "Push BTNctr");
until(ButtonPressed(BTNCENTER, TRUE));
Wait(BUTTON_PRESS_DELAY);
ClearLine(LCD_LINE8);
/****************** Trial 3 - Fails *****************************************/
msg_to_send = 0xc0000000 + 0x00310000 + rcvd_msg_id; // Fails
ClearLine(LCD_LINE2);
TextOut(0, LCD_LINE2, "Trial 3 Fails");
ClearLine(LCD_LINE6);
TextOut(0, LCD_LINE6, FormatNum("ACKm 0x%x", msg_to_send));
TextOut(0, LCD_LINE8, "Push BTNctr");
until(ButtonPressed(BTNCENTER, TRUE));
Wait(BUTTON_PRESS_DELAY);
ClearLine(LCD_LINE8);
/****************** Trial 4 - Fails *****************************************/
msg_to_send = 0xc0000000 + 0x310000 + rcvd_msg_id; // Fails
ClearLine(LCD_LINE2);
TextOut(0, LCD_LINE2, "Trial 4 Fails");
ClearLine(LCD_LINE6);
TextOut(0, LCD_LINE6, FormatNum("ACKm 0x%x", msg_to_send));
TextOut(0, LCD_LINE8, "Push BTNctr");
until(ButtonPressed(BTNCENTER, TRUE));
Wait(BUTTON_PRESS_DELAY);
ClearLine(LCD_LINE8);
/****************** Trial 5 - Works *****************************************/
msg_to_send = 0xc0310001; // Works
ClearLine(LCD_LINE2);
TextOut(0, LCD_LINE2, "Trial 5 Works");
ClearLine(LCD_LINE6);
TextOut(0, LCD_LINE6, FormatNum("ACKm 0x%x", msg_to_send));
TextOut(0, LCD_LINE8, "Push BTNctr");
until(ButtonPressed(BTNCENTER, TRUE));
Wait(BUTTON_PRESS_DELAY);
ClearLine(LCD_LINE8);
/****************** Trial 6 - Works Sometimes *******************************/
// data_digits = 0x310000; // Works
data_digits = I_NEED; // Works
msg_to_send = ACK_STUB + data_digits + rcvd_msg_id; // Works
ClearLine(LCD_LINE2);
TextOut(0, LCD_LINE2, "Trial 6 Works");
ClearLine(LCD_LINE3);
TextOut(0, LCD_LINE3, "Sometimes");
ClearLine(LCD_LINE6);
TextOut(0, LCD_LINE6, FormatNum("ACKm 0x%x", msg_to_send));
TextOut(0, LCD_LINE8, "Push BTNctr");
until(ButtonPressed(BTNCENTER, TRUE));
Wait(BUTTON_PRESS_DELAY);
ClearLine(LCD_LINE8);
/****************** End *****************************************************/
} // End of - File - hex_addition_test_02.nxc