Checksum on UART/ built in routines problems
Checksum on UART/ built in routines problems
Hello everyone
I´m posting here becouse I´m facing some problems with UART.
Ok, here is what I would like to do.
I want to read an analog input (witch is working) them transmit this value to another chip by UART.
The UART message is someting like this 2b(start of message) 0036 (what is going to be sent) ......(value of analog) ...(checksum).
Now is there anyone that could help me on creating a C code for this operation? Or where can I find usefull information about this?
Regards
I´m posting here becouse I´m facing some problems with UART.
Ok, here is what I would like to do.
I want to read an analog input (witch is working) them transmit this value to another chip by UART.
The UART message is someting like this 2b(start of message) 0036 (what is going to be sent) ......(value of analog) ...(checksum).
Now is there anyone that could help me on creating a C code for this operation? Or where can I find usefull information about this?
Regards
Last edited by mr_fonzie on 02 Jun 2015 12:23, edited 1 time in total.
Re: Checksum on UART
Ok here I´m again.
after compiling I´ve got the following error " assigning to non lvalue"
I would like to read the lower word from analogic and the uper word from analogic.
Code: Select all
#define Hi(param) ((char *)¶m)[1]
#define Lo(param) ((char *)¶m)[0]
char acc[1];
char analogic[1];
char anlgc2[1];
char anlgc1[2];
void interrupt() {
if (TMR0IF_bit=1)
{
TMR0IF_bit = 0; // clear TMR0IF
TMR0H = 0x3C;
TMR0L = 0xAF; //interrupção de 100ms
PORTB.B2=~PORTB.B2; // verificar se a interrupção se faz de 100ms em 100ms
val=ADC_Read(0); // lê o valor do ADC (0...1024)
delay_ms(10);
val1=(val*255/1023); // converte para 8 bits o ADC
PORTD=val1; // poe no port B os 8 bits do adc
val=val*32; // converte o valor do ADC
IntToHex(val,acc); // converte o valor do ADC em hexadecimal
IntToHex(val,analogic); // converte o valor do ADC em hexadecimal
anlgc1 = Hi(analogic); // this is not working
anlgc2 = Lo(analogic); // this is not working
}
}
I would like to read the lower word from analogic and the uper word from analogic.
Re: Checksum on UART
Hi.
Where is val and val1 variables declaration ?
Regards.
Where is val and val1 variables declaration ?
Regards.
Re: Checksum on UART
I´ve got it also declared
Code: Select all
int i=0,x=0;
int val,val1;
char acc[1];
char analogic[1];
char anlgc2[1];
char anlgc1[2];
bit oldstate;
bit arranc;
bit para;
Re: Checksum on UART more problems
hello again..
here is my problem now, I want to read the analog value(I can do it in the interrupt) then convert it to a double word (multiply it by 32) display it on a lcd. So far so good.
Now the problem is I want to get the lower word and higher word, but I´m finding some dificulties doing that.
I´ve use the Lo and Hi built-in routines no success..
Can some one help me?
Here is my complete code
I´m almost stuck in this on two weeks now..
Hope someone can help me
Regards
here is my problem now, I want to read the analog value(I can do it in the interrupt) then convert it to a double word (multiply it by 32) display it on a lcd. So far so good.
Now the problem is I want to get the lower word and higher word, but I´m finding some dificulties doing that.
I´ve use the Lo and Hi built-in routines no success..
Can some one help me?
Here is my complete code
Code: Select all
//#define Lo(analogic) ((char *)&analogic)[0]
//#define Hi(analogic) ((char *)&analogic)[1]
#define Lo(param) ((char *)¶m)[0]
#define Hi(param) ((char *)¶m)[1]
//#include <built_in.h>
//configuração do LCD
sbit LCD_RS at RB3_bit;
sbit LCD_EN at RB4_bit;
sbit LCD_D4 at RC0_bit;
sbit LCD_D5 at RC1_bit;
sbit LCD_D6 at RC2_bit;
sbit LCD_D7 at RC3_bit;
sbit LCD_RS_Direction at TRISB3_bit;
sbit LCD_EN_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
//fim de configuração do lcd
int i=0,x=0;
int val,val1,adcguarda;
unsigned char acc[4], adclcd[8];
//unsigned short analoglow, analoghi;
char analoglow[2], analoghi[2];
unsigned char anlgc2[2], anlgc1[2];
//------------------------------------------------------------------------------------//
//------------------------ interrupção -----------------------------------------------//
// interupção está ok no dia 16-12-2014
//------------------------------------------------------------------------------------//
void interrupt() {
if (TMR0IF_bit=1)
{
TMR0IF_bit = 0; // clear TMR0IF
TMR0H = 0x3C;
TMR0L = 0xAF; //interrupção de 100ms
PORTB.B2=~PORTB.B2; // verificar se a interrupção se faz de 100ms em 100ms
val=ADC_Read(0); // lê o valor do ADC (0...1024)
delay_ms(10); // analógico já esta a trabalhar.. 18-05-2015 pode-se por a interrupção mais rápido
val1=(val*255/1023); // converte para 8 bits o ADC
PORTD=val1; // poe no port B os 8 bits do adc
val=val*32; // converte o valor do ADC para enviar para o mc3phac
IntToHex(val,acc); // converte o valor do ADC em hexadecimal
IntToStr(val1, adclcd); // txt is " -4220" (one blank here)
//analoghi = Hi(acc); // devolve o byte mais alto
//delay_ms(1);
//analoglow = Lo(acc); // devolve o byte mais alto
//delay_ms(1);
}
}
/*
//------------------------------------------------------------------------------
//interrupção do ADC
//------------------------------------------------------------------------------
void interrupt_low() iv 0x0018
{
if (ADIF_bit == 1) //adc complete
{
ADIF_bit = 0;
delay_ms(1);
//val = ADC_Read(0); // le o valor de adc
//delay_ms(5);
//inttohex(val,acc); //converto o valor do adc em hexa para posteriormente enviar ao mc3phac
//PORTB.B2=1;
//LATD = val;
}
}
*/
void mostralcd()
{
delay_ms(1);
//IntToHex(analoghi,anlgc2);
//delay_ms(10);
//IntToHex(analoglow,anlgc1);
//delay_ms(10);
Lcd_Out(1,1,acc); // estou a apanhar o analógico de 0 a 1023
delay_ms(100);
Lcd_Out(2,1,adclcd);
delay_ms(100);
//Lcd_Out(2,6,anlgc1);
//delay_ms(100);
}
void Initialization()
{
INTCON = 0b11100000;
PIR1.ADIF =0; // quer dizer que a conversão analógica não esta terminada ======== isto é igual a isto PIR1.B6 =0;
RCON.IPEN = 0; //Abilita a prioridade nas interrupções mudei de 0 para 1 int1 a 1 habilita a prioridade
OSCCON = 0x00;
CMCON |= 7; // Disable comparators
ADCON0 = 0b00000001; // permite a conversão ADC no canal 0 RA0/ANO datasheet pag 241 estava ADCON0 = 0x01; 13-05-2015
ADCON1 = 0b10001110;
T0CON = 0x81;
TMR0H = 0x3C; //"carrega" o valor no timer0 para interrupção //TMR0 Preload = 64735; Actual Interrupt Time : 100ms
TMR0L = 0xAF; //"carrega" o valor no timer0 para interrupção //TMR0 Preload = 64735; Actual Interrupt Time : 100ms
}
void main()
{
TRISA = 0b00000001; //para leitura do analógico
TRISB = 0x00; // define o porto B como saída
TRISC = 0xE0; // define o porto C como entrada
TRISD = 0x00;
Initialization(void);
ADC_Init();
delay_ms(5);
Lcd_Init(); // Initialize LCD
delay_ms(1);
Lcd_Cmd(_LCD_CLEAR); // Clear display
delay_ms(1);
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
delay_ms(10);
Lcd_Out(2,1,"Afonso"); // teste do LCD
Lcd_Cmd(_LCD_CLEAR);
while(1)
{
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//visualização no lcd do analógico
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
mostralcd(void);
}
Hope someone can help me
Regards
- Aleksandar.Mitrovic
- mikroElektronika team
- Posts: 1697
- Joined: 11 Mar 2015 12:48
Re: Checksum on UART/ built in routines problems
Hi,
Can you please tell me which MCU are you using for this example?
Or attach your project in small zipped form how could I will be able to exam it thoroughly?
Best regards,
Aleksandar
Can you please tell me which MCU are you using for this example?
Or attach your project in small zipped form how could I will be able to exam it thoroughly?
Best regards,
Aleksandar
Re: Checksum on UART/ built in routines problems
Hello Aleksander
I´m using pic18f458 with 8MHz clock
I think I´ve made it. But there are some problems yet.
Whit this code I´m getting something like this on a lcd "00XX" for both low and hi.
on the image I got: 1st row 1st column the adcread converted to hex
1st row 2sd column hi value of adc
1st row 3rd column low value of adc
And my code
Now what i want to do is, like other messages I´ve prearrange, built a message from the adc read and send it through UART
The message is someting like
2b-> start of message
E4-> going to send 16bit
0062-> what is going to be send
HiLo adc reading converted to 16bit
check sum
I´ve made some calculations in the interrupt, but from what I´m seing I can not do the check sum calculation using integer numbers, I need to convert it to hexa and them do the checksum.
I do I add two numbers in hexa?
Hope you can help me.
Regards
I´m using pic18f458 with 8MHz clock
I think I´ve made it. But there are some problems yet.
Code: Select all
analoglow=Lo(val);
analoghi= Hi(val);
IntToHex(analoglow,anlgclo);
IntToHex(analoghi,anlgchi);
on the image I got: 1st row 1st column the adcread converted to hex
1st row 2sd column hi value of adc
1st row 3rd column low value of adc
And my code
Code: Select all
#define Lo(analogic) ((char *)&analogic)[0]
//#define Hi(analogic) ((char *)&analogic)[1]
//#define Lo(d) ((char *)&d)[0]
#define Hi(param) ((char *)¶m)[1]
//#include <built_in.h>
//configuração do LCD
sbit LCD_RS at RB3_bit;
sbit LCD_EN at RB4_bit;
sbit LCD_D4 at RC0_bit;
sbit LCD_D5 at RC1_bit;
sbit LCD_D6 at RC2_bit;
sbit LCD_D7 at RC3_bit;
sbit LCD_RS_Direction at TRISB3_bit;
sbit LCD_EN_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
//fim de configuração do lcd
// configuração do mc3phac
int RESET[7] = {0x2b, 0xE3, 0x10, 0x00, 0x30, 0x00, 0xDD}; // comando de reset
// 2b E3 10 00 30 00 DD
int SET_DEADTIME[7] = {0x2b, 0xe3, 0x00, 0x36, 0x30, 0x00, 0xb7}; //faz o dead time entre o desliga e liga das gates
// 2b E3 00 36 30 00 B7
int SET_PWM_POLARITY[7]={0x2b, 0xe3, 0x10, 0x00, 0x50, 0x00, 0xBD}; //faz a polaridade do pwm
// 2b e3 10 00 50 00 BD
int SET_PWM_FREQ[7] = {0x2b, 0xe3, 0x10, 0x00, 0x48, 0x00, 0xC5}; // define a frequencia do sinal de pwm
int SET_BASE_FREQ[7] = {0x2b, 0xe3, 0x10, 0x00, 0x61, 0x00, 0xAC}; //frequência base 61-> 50Hz
// 2b e3 10 00 61 00 AC
int SET_ACC[7] = {0x2b, 0xe4, 0x00, 0x60, 0x12, 0x00, 0xAA}; //tempo para acelerar de 0 as rpm definidas
int SET_SPEED[7] = {0x2b, 0xe4, 0x00, 0x62, 0x60, 0x00, 0x5A}; //velocidade do motor, este valor está entre 0x0000 e 0x7fff, para o check sum apenas tenho de calcular o lido do potênciometro e fazer o calculo.
int FORW[7] = {0x2b, 0xE3, 0x10, 0x00, 0x10, 0x00, 0xFD}; // " forward "
// 2b e3 10 00 10 00 Fd
int REV[7] = {0x2b, 0xE3, 0x10, 0x00, 0x11, 0x00, 0xFC}; // " reverse "
int STOP[7] = {0x2b, 0xE3, 0x10, 0x00, 0x20, 0x00, 0xED}; // " stop "
//leitura do seu estado
int READ_SETUP[5] = {0x2B, 0xd0, 0x00, 0xae, 0x82}; //lê o set up
int READ_STATUS[5] = {0x2B, 0xd0, 0x00, 0xC8, 0x68};
int i=0,x=0;
int val,val1,val2, val3, val4, analoglow, analoghi;
char acc[5], anlgchi[5], anlgclo[5],crc[5],crc1[5],crc2[5];
bit oldstate;
bit arranc;
bit para;
//------------------------------------------------------------------------------------//
//------------------------ interrupção -----------------------------------------------//
// interupção está ok no dia 16-12-2014
//------------------------------------------------------------------------------------//
void interrupt() {
if (TMR0IF_bit=1)
{
TMR0IF_bit = 0; // clear TMR0IF
TMR0H = 0x3C;
TMR0L = 0xAF; //interrupção de 100ms
PORTB.B2=~PORTB.B2; // verificar se a interrupção se faz de 100ms em 100ms
val=ADC_Read(0); // lê o valor do ADC (0...1024)
delay_ms(10); // analógico já esta a trabalhar.. 18-05-2015 pode-se por a interrupção mais rápido
val1=(val*255/1023); // converte para 8 bits o ADC
PORTD=val1; // poe no port B os 8 bits do adc
val=val*32; // converte o valor do ADC para enviar para o mc3phac
// várias conversões a serem feitas
intToHex(val,acc); // converte o valor do ADC em hexadecimal para o botão de start trabalhar e o lcd tmb esta função tem de ficar aqui
analoglow=Lo(val);
analoghi= Hi(val);
IntToHex(analoglow,anlgclo);
IntToHex(analoghi,anlgchi);
//cálculo do checksum
val2=98+analoghi+analoglow; //calculo de val2 é inteiro ->calculo do checksum consoante o analogico lido e já com o 2b e a msg.
val3=val2*(-1);
val3=val3+1;
val4=Lo(val3);
IntToHex(val2,crc);
IntToHex(val3,crc1);
} IntToHex(val4,crc2);
}
/*
//------------------------------------------------------------------------------
//interrupção do ADC
//------------------------------------------------------------------------------
void interrupt_low() iv 0x0018
{
if (ADIF_bit == 1) //adc complete
{
ADIF_bit = 0;
delay_ms(1);
//val = ADC_Read(0); // le o valor de adc
//delay_ms(5);
//inttohex(val,acc); //converto o valor do adc em hexa para posteriormente enviar ao mc3phac
//PORTB.B2=1;
//LATD = val;
}
}
*/
void mostralcd()
{
Lcd_Out(1,1,acc); // estou a apanhar o analógico de 0 a 1023
delay_ms(15);
Lcd_Out(1,6,anlgchi); // menos significativo de acc
delay_ms(15);
Lcd_Out(1,11,anlgclo); // mais significativo de acc
delay_ms(15);
Lcd_Out(2,1,crc); // valor da soma 2b+62+hi+lo
delay_ms(15);
Lcd_Out(2,6,crc1); // crc not +1
delay_ms(15);
Lcd_Out(2,11,crc2); // valor final do checksum
delay_ms(15);
}
void Initialization()
{
INTCON = 0b11100000;
PIR1.ADIF =0; // quer dizer que a conversão analógica não esta terminada ======== isto é igual a isto PIR1.B6 =0;
RCON.IPEN = 0; //Abilita a prioridade nas interrupções mudei de 0 para 1 int1 a 1 habilita a prioridade
OSCCON = 0x00;
CMCON |= 7; // Disable comparators
ADCON0 = 0b00000001; // permite a conversão ADC no canal 0 RA0/ANO datasheet pag 241 estava ADCON0 = 0x01; 13-05-2015
ADCON1 = 0b10001110;
T0CON = 0x81;
TMR0H = 0x3C; //"carrega" o valor no timer0 para interrupção //TMR0 Preload = 64735; Actual Interrupt Time : 100ms
TMR0L = 0xAF; //"carrega" o valor no timer0 para interrupção //TMR0 Preload = 64735; Actual Interrupt Time : 100ms
/*
TXSTA = 0b00100100; //talvez tenha de mudar o spbrg para 1
RCSTA = 0b10010000; //configurações do usart
RCIE_bit =1; //abilita a interrupção de recepção do uart ainda não é utilizado
TXIE_bit =1; //abilita a interrupção de envio do uart
RCIF_bit =0; // flag de recepção completa
TXIF_bit =0; // flag de envio completa
*/
}
void main()
{
TRISA = 0b00000001; //para leitura do analógico
TRISB = 0x00; // define o porto B como saída
TRISC = 0xE0; // define o porto C como entrada
TRISD = 0x00;
UART1_Init(9600); //Arranca com o baud rate do usart a 9600
oldstate = 0;
arranc = 1;
para = 0;
Initialization(void);
ADC_Init();
delay_ms(5);
Lcd_Init(); // Initialize LCD
delay_ms(1);
Lcd_Cmd(_LCD_CLEAR); // Clear display
delay_ms(1);
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(2,1,"Afonso"); // teste do LCD
delay_ms(10);
Lcd_Cmd(_LCD_CLEAR);
//1 envio do reset
for(i=0;i<7;i++)
{
UART1_Write(RESET[i]);
}
delay_ms(5);
//2 configuração do dead time
for(i=0;i<7;i++)
{
UART1_Write(SET_DEADTIME[i]);
}
delay_ms(5);
// vamos por aqui um "if" se for igual ao resultado da recepção do uart prosseguimos
//3 configuração da polaridade do pwm
for(i=0;i<7;i++)
{
UART1_Write(SET_PWM_POLARITY[i]);
}
//4 configuração da frequencia do sinal de pwm a 21.1kHz
for(i=0;i<7;i++)
{
UART1_Write(SET_PWM_FREQ[i]);
}
delay_ms(5);
//5 configuração dos 50Hz
for(i=0;i<7;i++)
{
UART1_Write(SET_BASE_FREQ[i]);
}
delay_ms(5);
//6 configuração da aceleração
for(i=0;i<7;i++)
{
UART1_Write(SET_ACC[i]);
}
delay_ms(5);
//7 configuração da velocidade
for(i=0;i<7;i++)
{
UART1_Write(SET_SPEED[i]);
}
delay_ms(5);
// comando de STOP para garantir que fica mesmo em STOP
for(i=0;i<7;i++)
{
UART1_Write(STOP[i]);
}
delay_ms(100);
while(1)
{
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//ordem de arranque
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
if (Button(&PORTC, 5, 0, 1) && arranc ) // Detect logical one
{
//PORTB = 0x01; //turn on port B
PORTB.B0=1;
for(i=0;i<7;i++)
{
UART1_Write(FORW[i]);
}
PORTB.B1=1;
delay_ms(100);
/*
// envia o valor de aceleração
for(x=0;x<2;x++)
{
//UART1_Write("Afonso");
UART1_Write_Text("Afonso");
}
delay_ms(500); */
PORTB.B1=0;
oldstate = 1;
arranc = 0; // Update flag
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//ordem de paragem
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
if (oldstate && Button(&PORTC, 5, 1, 0))
{ // Detect one-to-zero transition
PORTB = 0x00; //turn off port B
for(i=0;i<7;i++)
{
UART1_Write(STOP[i]);
}
oldstate = 0; // Update flag
arranc = 1;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//visualização no lcd do analógico
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
mostralcd(void);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//actualização da velocidade
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*
if(veldif)
{
for(i=0;i<7;i++)
{
UART1_Write(SET_SPEED[i]);
}
}
val = ADC_Read(1); // le o valor de adc
delay_ms(20);
val1=val/1024;
delay_ms(5); */
}
Now what i want to do is, like other messages I´ve prearrange, built a message from the adc read and send it through UART
The message is someting like
2b-> start of message
E4-> going to send 16bit
0062-> what is going to be send
HiLo adc reading converted to 16bit
check sum
I´ve made some calculations in the interrupt, but from what I´m seing I can not do the check sum calculation using integer numbers, I need to convert it to hexa and them do the checksum.
I do I add two numbers in hexa?
Hope you can help me.
Regards
Re: Checksum on UART/ built in routines problems
Hello everyone
I think I´ve do with the hi and lo.
Now the problem is, I want to pick the lo and hi values and a check sum value store them and send them in the following order.
SET_SPEED[5]=anlgchi; //save the analogic hi value in hexa at position 5 of SET_SPEED
SET_SPEED[6]=anlgclo; //save the analogic lo value in hexa at position 6 of SET_SPEED
SET_SPEED[7]=crc2; //save check sum value in hexa at position 7 of SET_SPEED
int SET_SPEED[7] = {0x2b, 0xe4, 0x00, 0x62, SET_SPEED[5], SET_SPEED[6], SET_SPEED[7]};
Thi code is giving me the following error "implicit conversion of pointer to int mikroc"
Regards
I think I´ve do with the hi and lo.
Now the problem is, I want to pick the lo and hi values and a check sum value store them and send them in the following order.
SET_SPEED[5]=anlgchi; //save the analogic hi value in hexa at position 5 of SET_SPEED
SET_SPEED[6]=anlgclo; //save the analogic lo value in hexa at position 6 of SET_SPEED
SET_SPEED[7]=crc2; //save check sum value in hexa at position 7 of SET_SPEED
int SET_SPEED[7] = {0x2b, 0xe4, 0x00, 0x62, SET_SPEED[5], SET_SPEED[6], SET_SPEED[7]};
Thi code is giving me the following error "implicit conversion of pointer to int mikroc"
Regards
- Aleksandar.Mitrovic
- mikroElektronika team
- Posts: 1697
- Joined: 11 Mar 2015 12:48
Re: Checksum on UART/ built in routines problems
Hi,
I'm glad that you managed to separate High from Low.
Can you attach your project in small zipped form how could I will be able to exam your code?
Best regards,
Aleksandar
I'm glad that you managed to separate High from Low.
Can you attach your project in small zipped form how could I will be able to exam your code?
Best regards,
Aleksandar
Re: Checksum on UART/ built in routines problems
Hello Aleksander
Here is my code.
Now what I want to do is something like this
SET_SPEED[5]=*anlgchi; //save the hi value of analogic at SET_SPEED[5]
SET_SPEED[6]=*anlgclo; //save the lo value of analogic at SET_SPEED[6]
SET_SPEED[7]=*crc2; //save the crc value at SET_SPEED[7]
Then send the command through UART.
Here is my code.
Now what I want to do is something like this
SET_SPEED[5]=*anlgchi; //save the hi value of analogic at SET_SPEED[5]
SET_SPEED[6]=*anlgclo; //save the lo value of analogic at SET_SPEED[6]
SET_SPEED[7]=*crc2; //save the crc value at SET_SPEED[7]
Then send the command through UART.
- Attachments
-
- uartenvia.rar
- (3.53 KiB) Downloaded 77 times
Re: Checksum on UART/ built in routines problems
update not good
When I use the following code
SET_SPEED[7]=*crc2; //save the crc value at SET_SPEED[7]
The stop command sent by uart is not ok.
What a hell?????
When I use the following code
SET_SPEED[7]=*crc2; //save the crc value at SET_SPEED[7]
The stop command sent by uart is not ok.
What a hell?????
- Aleksandar.Mitrovic
- mikroElektronika team
- Posts: 1697
- Joined: 11 Mar 2015 12:48
Re: Checksum on UART/ built in routines problems
Hi,
I tried your code and compile without errors.
Can you tell me did you test this code on some real hardware?
Best regards,
Aleksandar
I tried your code and compile without errors.
Can you tell me did you test this code on some real hardware?
Best regards,
Aleksandar
Re: Checksum on UART/ built in routines problems
Hello Aleksander
Yes I´ve tried the code on hardware, and check it, but it was only before adding the analog code. By that time all worked correct.
The code I wrote above is correct? Let´s say I want to save the hi an lo part of analog on set-speed? Ten send it like this
0x2B start of message
0xe4 lengh of message
0x00 lengh of message
0x62 what command
0xhi adc hi value
0xlo ad low value
0xcrc check sum
Yes I´ve tried the code on hardware, and check it, but it was only before adding the analog code. By that time all worked correct.
The code I wrote above is correct? Let´s say I want to save the hi an lo part of analog on set-speed? Ten send it like this
0x2B start of message
0xe4 lengh of message
0x00 lengh of message
0x62 what command
0xhi adc hi value
0xlo ad low value
0xcrc check sum
- Aleksandar.Mitrovic
- mikroElektronika team
- Posts: 1697
- Joined: 11 Mar 2015 12:48
Re: Checksum on UART/ built in routines problems
Hi,
If I understand you correctly you need to add Hi (9-16 bits) and Lo(0-8 bits) of ADC readings to the position 5 and 6 in string of 7 members and checksum on position 7?
Then I suggest you to write like this:
Since all values are 8 bit there is no need for int you can use char type.
Also there is no need to make 8 bit ADC reading from 10.
Since Hi and Lo functions take 8 bits of high and low value.
Can you explain me what are you trying to do whit the rest of the code?
Best regards,
Aleksandar
If I understand you correctly you need to add Hi (9-16 bits) and Lo(0-8 bits) of ADC readings to the position 5 and 6 in string of 7 members and checksum on position 7?
Then I suggest you to write like this:
Code: Select all
//char SET_SPEED[7] = {0x2b, 0xe4, 0x00, 0x62, SET_SPEED[4], SET_SPEED[5], SET_SPEED[6]};
SET_SPEED[4]=anlgchi;
SET_SPEED[5]=anlgclo;
SET_SPEED[6]=crc2;
Also there is no need to make 8 bit ADC reading from 10.
Since Hi and Lo functions take 8 bits of high and low value.
Can you explain me what are you trying to do whit the rest of the code?
Best regards,
Aleksandar
Re: Checksum on UART/ built in routines problems
Hello Aleksander
The code you wrote above, thats just wat I want to do, in my mind..
Ok but when I have it on my compiler it says implicit convertion of point to int in thay specific code line.
About the rest of the code.
I´m using mc3phac and a pic 18f458. The pic will send varios commands throught UART to the mc3. The ADC value is to chage the actual speed of an assyncronos motor.
I´ve the rest of the code working but the speed(ADC) is not working yet.
Regards
The code you wrote above, thats just wat I want to do, in my mind..
Ok but when I have it on my compiler it says implicit convertion of point to int in thay specific code line.
About the rest of the code.
I´m using mc3phac and a pic 18f458. The pic will send varios commands throught UART to the mc3. The ADC value is to chage the actual speed of an assyncronos motor.
I´ve the rest of the code working but the speed(ADC) is not working yet.
Regards