Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/04/04 08:40
Read: times


 
#61872 - RE: ***Details***
Responding to: ???'s previous message

As mentioned previously, it is bad practice to sit in a interrupt routine for too long. The general idea is to get the data and get out of an interrupt ASAP. For your problem, the four sensor bytes need to be put into a buffer. How the 2051 sends the data you have not mentioned therefore your receive code needs to be able to figure out when the first sensor data is being sent so it can synchronise the storage into the buffer. Assuming this is under control, once you have the four sensor values you need to activate a routine to process these values (not in the interrupt!).


for example my protocol has 0xff as the beginning of packet header and the sensor values must not equal 0xff.

char sensor_buffer[4];
bit RX_Complete = 0;

main()
{
....init etc

if (RX_Complete) //if sensor inputs available...
{
RX_Complete = 0;
...process inputs
}

}

rx_interrupt(void)
{
static char rx_byte;
static byte *rx_ptr = sensor_buffer;

if (RI)
{
rx_byte = SBUF;
RI = 0;
if (rx_byte == 0xff) //if start token received
{
rx_ptr = sensor_buffer;
}
else //must be a sensor value
{
if (rx_ptr < (sensor_buffer + sizeof(sensor_buffer)))
{
*rx_ptr = rx_byte;
rx_ptr++;
if (rx_ptr == (sensor_buffer + sizeof (sensor_buffer))) RX_Complete = 1;
}
}

}

I could've done the above code in assembler but I did it in 'c' to concentrate on the logic rather than the implementation. I would write my asm code using the same program logic.

Your mainline code should process in the following manner:

1/ get inputs
2/ process inputs
3/ update outputs

Hopefully this may point you in the direction of success.


List of 12 messages in thread
TopicAuthorDate
Sbuf value "refresh"?            01/01/70 00:00      
   RE: Sbuf value "refresh"?            01/01/70 00:00      
   RE: Sbuf value \\            01/01/70 00:00      
      RE: Sbuf value            01/01/70 00:00      
         RE: Sbuf value            01/01/70 00:00      
   RE: Sbuf value \\\\\\\\            01/01/70 00:00      
      ***Details***            01/01/70 00:00      
         RE: ***Details***            01/01/70 00:00      
   RE: Sbuf value "refresh"?            01/01/70 00:00      
      RE: Sbuf value \            01/01/70 00:00      
         RE: Sbuf value \            01/01/70 00:00      
         Silly problem solved...            01/01/70 00:00      

Back to Subject List