PetrM,
Sorry for the late response - I didn't realize there was any activity on the thread until now (I must have negelected to enable the notifications for the message).
Also, thank you for your replies. I haven't tried implementing the code you provided yet, but I reviewed it carefully and it seems to be doing what I have (below). The code produces address bytes most of the time, however often they come out as data bytes (parity type bit 0). I have tried with both polled and interrupt drivers, with similar results. Do you see any problems with what I've done?
//Sends first byte of message as address, and remaining bytes as data.
//Automatically calculates checksum and appends it to the packet (as data).
void MDB_send_msg (FILE_PTR fh_ptr, char *msg, uint_8 len) {
uint_8 i;
char chk_sum = 0;
uint_8 init_UMR;
printf ("MDB_send_msg, len: %d, msg: ", len);
for (i=0; i<len; i++) {
printf ("0x%02X ", msg[i]);
chk_sum += msg[i]; //accumulate checksum
}
printf ("\n");
//First byte is address parity type
MCF_UART1_UCR = MCF_UART_UCR_RESET_MR; //reset the internal pointer to UMR1
init_UMR = MCF_UART1_UMR & ~MCF_UART_UMR_PM_MULTI_ADDR; //get the current value and clear the Parity Type (PT) and Parity Mode (PM) bits
MCF_UART1_UCR = MCF_UART_UCR_RESET_MR; //reset the internal pointer to UMR1
MCF_UART1_UMR = init_UMR | MCF_UART_UMR_PM_MULTI_ADDR; //set mode to multidrop for address character
write(fh_ptr,msg,1); //send address/command
//Remaining bytes are all data parity type
MCF_UART1_UCR = MCF_UART_UCR_RESET_MR; //reset the internal pointer to UMR1
init_UMR = MCF_UART1_UMR & ~MCF_UART_UMR_PM_MULTI_ADDR; //get the current value and clear the Parity Type (PT) and Parity Mode (PM) bits
MCF_UART1_UCR = MCF_UART_UCR_RESET_MR; //reset the internal pointer to UMR1
MCF_UART1_UMR = init_UMR | MCF_UART_UMR_PM_MULTI_DATA; //set mode to multidrop for data character
if (len > 1) {
msg++; //increment msg pointer
write(fh_ptr,msg,len-1); //send data bytes
}
write(fh_ptr,&chk_sum,1); //send checksum
}
I also wanted to ask about the code you sent, regarding this line:
tmp = io_info_ptr->INIT.UMR1_VALUE & ~MCF52XX_UART_UMR1_MD_ADDRESS;
Is it guaranteed that the UMR pointer will already be reset at this point? I wasn't sure so I have it resetting every time it changes the parity type.
My second problem comes when I try to receive. I'm trying to check the received parity type using the code below ( if (MCF_UART1_USR & MCF_UART_USR_PE) ), but it always returns as data type, even when the data coming in is address type.
//Returns received message up to first address byte, and length including checksum byte.//If no address byte is received within timeout, return false. Message buffer and length will contain message received up to point of timeout.uint_8 MDB_read_msg (FILE_PTR fh_ptr, char *msg, uint_8 *len, TIME_STRUCT timeout) { TIME_STRUCT StartTime, CurrentTime, TimeDifference; char c; printf ("MDB_read_msg: "); _time_get(&StartTime); //Get start time *len = 0; do { if (fstatus(fh_ptr)) { c = fgetc(fh_ptr); if (c==IO_ERROR) break; *msg = c; msg++; len++; printf ("0x%02X ", c); //all messages from MDB peripherals must end with an address byte if (MCF_UART1_USR & MCF_UART_USR_PE) { printf ("\n"); return TRUE;
} } _time_get(&CurrentTime); _time_diff(&StartTime, &CurrentTime, &TimeDifference); } while((TimeDifference.SECONDS >= timeout.SECONDS) &&
(TimeDifference.MILLISECONDS >= timeout.MILLISECONDS)); printf ("timed out\n"); return FALSE;}
Thanks again for your help,
Angelo