View previous topic :: View next topic |
Author |
Message |
Manu59114
Joined: 22 Jan 2018 Posts: 34 Location: North of France
|
bgetc circular buffer stop |
Posted: Tue Apr 03, 2018 8:58 am |
|
|
Hello to all,
I use the circular buffer from the CCS example to receive data from the uart and everything is fine except at one moment.
If i stop sending data to the receiver and the middle of the transmission. (sent only 5 characters for example)
The receiver stop exactly just before this instruction:
Code: |
Receive_Array[numero_case_dans_tableau] = bgetc();
|
The PIC is not crashed but waiting for something somewhere but i don't know what and where!!
Timer 0 is not counting....
At this moment, if i turn on the data from the sender, the receiver back the live!
Code: |
If(next_in!=next_out)
{
printf("A\r"); // to test
If(bgetc()=='*') // Aller récupérer un caractère dans le buffer "bgetc()" et le comparer avec 0x2a ou '*'ascci
{
do
{
printf("B\r"); //to show where i'm in the function
Receive_Array[NCDT]= bgetc();
// mettre ce caractère dans la prochaine case du tableau. c'est à dire la case 0
Receive_Array[NCDT]=data_from_circular_buffer;
NCDT++; // incrémenter. ajouter 1 à NCDT
}
while(NCDT!=NCDT_Default); // NCDT_Default == 49
NCDT=0; // case tableau à 0
}
}
Treat_Data_Array();
|
Do you have an idea where it is blocked?
Thank you very much to all.
MAnu _________________ CCS + ICD3 + PIC18F46K80 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Tue Apr 03, 2018 10:55 am |
|
|
Bgetc, will wait if there is no data available. So you need to test if (bkbhit), before calling it, or the code will hang. |
|
|
Manu59114
Joined: 22 Jan 2018 Posts: 34 Location: North of France
|
|
Posted: Tue Apr 03, 2018 3:20 pm |
|
|
I changed like this and the problem still the same!
Is it the right place to test Bkbhit ?
Code: |
If(next_in!=next_out)
{
printf("A\r"); // to test
If(bgetc() == '*') // Aller récupérer un caractère dans le buffer "bgetc()" et le comparer avec 0x2a ou '*'ascci
{
do
{
if(bkbhit)
{
printf("B\r"); //to test
// get the next character
Receive_Array[NCDT] = bgetc();
// mettre ce caractère dans la prochaine case du tableau. c'est à dire la case 0
Receive_Array[NCDT] = data_from_circular_buffer;
NCDT++; // incrémenter. ajouter 1 à NCDT
}
else
{
}
}
while(NCDT != NCDT_Default); // NCDT_Default == 49
NCDT=0; // array position at 0
}
}
Treat_Data_Array();
|
Thank you to all.
wish you a great day. _________________ CCS + ICD3 + PIC18F46K80 |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Wed Apr 04, 2018 12:58 am |
|
|
When do you think you will exit this loop with no data arriving.
Code: | while(NCDT != NCDT_Default); |
|
|
|
|