Po drugiej strone urzadzenia konwertuje dwa chary na int w taki sposob
Kod: Zaznacz cały
VUV=uart_rx_buf[2];
VUV|=(uart_rx_buf[3]<<8);
Napisałęm funkcje, do ktorej wrzucam moja zmienna 16 bit val, pobiera jej adres, kopiuje do bufora pierwszy bajt, zwieksza adres i kopiuje do nastepnej komorki bufora.
Zastanawiam sie w czym problem bo po drugiej stronie odbieram kompletnie co innego.
Czy program jest poprawny? Pierwszy raz uzywam wskaznikow i mam pewne watpliwosci.
Kod: Zaznacz cały
unsigned char add_to_tx_buffer(void *val, unsigned char *buf_tx, unsigned char idx, unsigned char bytes)
{
unsigned char *val_ptr;
val_ptr=(unsigned char*)&val;
for(unsigned char i=0;i<bytes;i++)
{
buf_tx[idx]=*val_ptr;
val_ptr++;
idx++;
}
return idx;
}
void uart_send( void )
{
char *ptr;
long int buf_send;
unsigned char buf_idx=0;
if(uart_data_tx_idx==0)
{
//uart_tx_buf[0]=Num_Cells;
//uart_tx_buf[1]=Num_ltcs;
buf_idx+=add_to_tx_buffer(&Num_Cells, uart_tx_buf, buf_idx, 1);
buf_idx+=add_to_tx_buffer(&Num_ltcs, uart_tx_buf, buf_idx, 1);
buf_idx+=add_to_tx_buffer(&VUV_const, uart_tx_buf, buf_idx, 2);
buf_idx+=add_to_tx_buffer(&VOV_const, uart_tx_buf, buf_idx, 2);
.....