Hello together, I got stuck a bit. Maybe someone could push me into right direction. I am sending and receiving data with my F2806. Depending on type of function I receive in my requst, I know the expected amount of bytes, which the request should contain. What I am worrying about is, if some byte would get lost, then I would get stuck in my "getchar" function. Therefore I have tried to implement a timer, which should help me to leave the "getchar" loop in case one or more bits are missing, got lost. But it doesnt work properly. Here some code,
Here I am starting my timer, and calling my function to read data from RXBUF (n could be any number ( 6 - 10), depending on the received function in request)
StartCpuTimer1();
for (i = 1; i <n; i++)
{
rx_buf[i] = serial_port_getchar(&SciRegstr);
test_variable=rx_buf[i];
ReloadCpuTimer1();
}
StopCpuTimer1();
My function to read data from RXBUF, here I took 0xFFF0BDBF as threshold (I just wanted to wait some fixed time (0,01 sec), here 100MHz quartz -> number_of_cycles= 0,01(s)/(10ns) = 1.000.000cycles -> 1.000.000cycles=0xF4240 -> timer initialized with "CpuTimer1Regs.PRD.all = 0xFFFFFFFF;" no prescaler ->
0xFFFFFFFF-0xF4240=0xFFF0BDBF, that means timer has to count down from 0xFFFFFFFF to 0xFFF0BDBF and the while condition will be fullfilled
unsigned char serial_port_getchar(struct REG_VARS *p2_register)
{
while((p2_register->reg_type->SCIFFRX.bit.RXFFST==0) && (CpuTimer1Regs.TIM.all > 0xFFF0BDBF));// (timer0_period)));
return (p2_register->reg_type->SCIRXBUF.all);
}
My problem is I am not able to receive whole data correctly, doestn matter wich timer I am using for "CpuTimer1Regs.TIM.all" condition.
Do I miss something? I have spent the whole weekend to solve this, but I am running against a wall!
Does anyone have any suggestion?
Thanks
Bye