Pigi_102
Member level 2
Hi all.
I' m wirting a code to decode a signal from a source.
The source sends out a bit train in this fashion: 10100000 10100001 10100010 10100011
In my code I read this data train and write it in hex in the internal eeprom.
I wrote the routine and checkd in mplab using some test code in this way:
just outside the while loop.
In the get_data
I write to eeprom the bit received and the computed value:
When I read the eeprom value outside the while loop ( tr previous strcpy/strcat part )I read 01 00 01 00 00 00 00 00 A0 FE and it's exactly what I do expect.
The main loop is:
When the program is in the while loop in the eeprom I read: 01 00 01 00 00 00 00 00 00 FE
So the last byte seem that is has not get computed.
The are no interrupt in the code, but hell if I can understand why it's working this way.
The PIC is a 16F1826,
The compiler is CCS PCWHD 5.008
Do you have any idea ?
Thanks
Pigi
I' m wirting a code to decode a signal from a source.
The source sends out a bit train in this fashion: 10100000 10100001 10100010 10100011
In my code I read this data train and write it in hex in the internal eeprom.
I wrote the routine and checkd in mplab using some test code in this way:
just outside the while loop.
In the get_data
I write to eeprom the bit received and the computed value:
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 int8 get_data(int8 start_address) { int8 ret = 0; int8 i; for (i = (start_address); i < (start_address) + 8; i++) { ret <<= 1; if(pckt_bits[i] == '1') ret |= 1; write_eeprom(address,pckt_bits[i]); address++; } write_eeprom(address,ret); address++; write_eeprom(address,254); // Stop indicator address++; return ret; }
When I read the eeprom value outside the while loop ( tr previous strcpy/strcat part )I read 01 00 01 00 00 00 00 00 A0 FE and it's exactly what I do expect.
The main loop is:
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 while(1){ for(pckt_bits_pos=0; pckt_bits_pos < PACKET_BITS ; pckt_bits_pos++){ while (input(CLK)); // Wait for clock low pckt_bits[pckt_bits_pos] = input_state(DI); while (!input(CLK)); // wait for clock high } data= get_data(); for (pckt_bits_pos = 0; pckt_bits_pos < PACKET_BITS; pckt_bits_pos++) { pckt_bits[pckt_bits_pos] = 0; } }
When the program is in the while loop in the eeprom I read: 01 00 01 00 00 00 00 00 00 FE
So the last byte seem that is has not get computed.
The are no interrupt in the code, but hell if I can understand why it's working this way.
The PIC is a 16F1826,
Code C - [expand] 1 2 3 4 5 6 7 8 #FUSES NOBROWNOUT //No brownout reset #FUSES INTRC_IO //Internal Oscillator #FUSES NOWDT //No Watch Dog Timer #FUSES NOPUT //No Power Up Timer #FUSES NOPROTECT //Code not protected from reading #FUSES MCLR //Master Clear pin enabled #FUSES NOLVP //Low Voltage Programming on B3(PIC16) or B5(PIC18) #FUSES NOCPD //No EE protection
The compiler is CCS PCWHD 5.008
Do you have any idea ?
Thanks
Pigi