Projet

Général

Profil

« Précédent | Suivant » 

Révision 893

Ajouté par beclement2 il y a environ 4 ans

Rectrame fonctionnel sans checksum

Voir les différences:

sp4c12.c
//On d?finit notre baud rate
u0brg = 0x20;
//Configuration transmission de donn?es
crd_u0c0 = 1;
crs_u0c0 = 0;
te_u0c1 = 1;
//Configuration r?ception de donn?es
crd_u0c0 = 1;
crs_u0c0 = 0;
re_u0c1 = 1;
}
void uart0_tx(char c){
void uart0_tx(char c){ //Fonction permettant de translettre un signal
crd_u0c0 = 1;
crs_u0c0 = 0;
te_u0c1 = 1;
while(!ti_u0c1);
u0tb = c;
te_u0c1 = 0;
}
char uart0_rx(void){
char uart0_rx(void){ //Fonction permettant de recevoir un signal
char c;
crd_u0c0 = 1;
crs_u0c0 = 0;
re_u0c1 = 1;
while(!ri_u0c1);
......
return c;
}
int rectrame(char * buffer){
int hex2int(char *c){
int i;
int retour;
for (i=0;i<2;i++){
if (c[i]>='0' && c[i]<='9'){
c[i] = c[i] - 48;
}
if(c[i] = c[i] >= 'A'){
c[i] = c[i] - 55;
}
}
retour = c[1] + 16 * c[0];
return retour;
}
int rectrame(char * buffer){ // Fonction r?cup?rant les trames
int i = 1;
char c;
int j = 0;
char d;
int check = 0;
int temp;
// char checksum_trame[2];
while(uart0_rx() != '$');
buffer[0] = '$';
while((c = uart0_rx())!= '*'){
// check = check ^ c; //Test checksum
buffer[i] = c;
i++;
}
buffer[i] = '*';
return i;
// checksum_trame[0] = uart0_rx(); Test Checksum
// checksum_trame[1] = uart0_rx();
// temp = hex2int(checksum_trame); //Test checksum
/*if(temp != check){ // Test checksum
return 0;
}
else{*/
return i;
//}
}
......
int i;
int j;
char c;
uart0_init();
uart0_init(); // On initialise
// v = uart0_rx();
while (1){
......
char trame[128];
int j;
i = rectrame(trame);
for (j=0; j<=i; j++){
i = rectrame(trame); // On r?cup?re la trame
for (j=0; j<=i; j++){ // On transmet pour voir si on a bien re?u
uart0_tx(trame[j]);
}

Formats disponibles : Unified diff