SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on how to get your MSP JTAG programmer up and running.
By naseri.m
#67574
hi members!
I wanted to send a command frame by uart my initialization is correct but I want to know how can the program understand the frame is finish and star to process it?
my frame is:
typedef struct
{
char StartOfFrame; // 1 byte for SOF
char SequenceNumber; // 1 byte for sequence Number
char CommandType; // 1 byte for event type
char ChannelNum; // 1 byte channel Number
char Parameter[BYTE_PER_CMD_PARAMETER]; // 2 byte for parameters
} _Command_frame;


I wore the uart state in state machine's form :
void Uart_StateHandler( char Byte)
{
_Command_frame myCommand;
signed char t_BuffLoad;

switch (ReceiveState)
{
////////////////////////////
case UART_HEADER:
if (Byte == COMMAND_HEADER)
ChangeUart_State(UART_SEQUENCE_NUM);
break;
////////////////////////////
case UART_SEQUENCE_NUM:
ReceivedCommands.SequenceNumber = Byte;
ChangeUart_State(UART_CHANNEL_NUM);
break;
////////////////////////////
case UART_CHANNEL_NUM:
ChangeUart_State(UART_COMMANDTYPE);
ReceivedCommands.ChannelNum = Byte;
break;
////////////////////////////
case UART_COMMANDTYPE:
ChangeUart_State(UART_PARAMAMETER_12);
ReceivedCommands.CommandType = Byte;
break;
////////////////////////////
case UART_PARAMAMETER_12:
ChangeUart_State(UART_PARAMAMETER_34);
ReceivedCommands.Parameter[12] = Byte;
break;
////////////////////////////
case UART_PARAMAMETER_34:
ReceivedCommands.Parameter[34] = Byte;
WriteCommandQueues(&CommandQueues, &ReceivedCommands); // add Command into queue
ChangeUart_State(UART_HEADER);
break;
/////////////////////////////////
case UART_LASTBYTE:
if (Byte == LAST_CMND_BYTE )
{

ChangeUart_State(UART_HEADER);
}
break;
}
}
IN lastbyte state I want to recognize that what command must execute at that time and I dont know how?
By naseri.m
#67626
hi again!
another guesting is:
how can I understand that this frame read by program ?
I mean after making the frame and call the process command queues ,can I be sure abut preprocessing the frame? and how?
By gm
#67637
Is your state machine in the interrupt handler? If so, one normally posts the received data to a queue for background processing, i.e. in the loop that polls the queue to see if there is any data to be processed.

If the state machine is not in the interrupt handler then you should just be able to call your function that processes the command in the last state.

gm
By naseri.m
#67671
hi !
thanks for your reply
this is my interrupt routine:
#pragma vector=UART0RX_VECTOR
__interrupt void usart0_rx (void)
{
char Byte;
while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready?

Uart_StateHandler(Byte); /

}
I want to know :is it necessary to add the code for reset tx and rx in this routine?
the oder problem that I have is:
when I debug the program,it is going to uart state but just first case and when I breakpoint on the second case the debugger stopped and the message is:
could not get target status!!
I don't know where do I make a mistake and what am i doing for it!??