Note that using SetHPTimerAfterNow can (and will) cause timing drift, you may want to compensate for that somehow (by using that usec counter for example).
Another note: using the HP timer with that high repetition rate may cause problems. I'd recommend you to use a much slower loop to check for a 'start' signal (longer pulse), and switch to the high resolution timer when that arrives. This is for the receiver end of course.
Thanks for the tips, I'll probably check the input every 10 ms or so.
Is it possible to instead of setting the timer after now, to set it at a particular time (based on checking the usec counter). If this isn't possible, I might just run a continuous loop that checks the input, and reads the usec counter when it changes.
After some work and much
distractions (please don't click the link if your a developer, we wouldn't want CHDK development to come to a sudden halt

) I've written some experimental code to transmit and receive a 16 bit packet.
However, it won't compile, giving the following error (amongst other identical errors with other functions)
../generic/wrappers.c: In function 'master_send_bit':
../generic/wrappers.c:1990:41: error: 'master_send_space' undeclared (first use in this function)As master_send_bit is declared before master_send_space. But if I were to swap them around, it would be vice-versa. Any ideas on how I could get around this?
Here's some of the code in question:
int master_send_bit()
{
*((volatile int *) MASTER_OUTPUT_ADDRESS) = MASTER_OUTPUT_MAGIC_NUMBER_ON;//Set LED on
if (master_message_buffer & (1 << master_bit_number)) //Check if the next bit is a 1
{
_SetHPTimerAfterNow(MASTER_BIT_1_DELAY,master_send_space,master_send_space,0);//delay for 1
}
else
{
_SetHPTimerAfterNow(MASTER_BIT_0_DELAY,master_send_space,master_send_space,0);//delay for 0
}
master_bit_number++; //Should hopefully increase before master_send_space runs
}
int master_send_space()
{
*((volatile int *) MASTER_OUTPUT_ADDRESS) = MASTER_OUTPUT_MAGIC_NUMBER_OFF;//Set LED off
if(master_bit_number == 16) //data transmission has finished.
{
_SetHPTimerAfterNow(MASTER_END_DELAY,master_end_transmission,master_end_transmission,0);
}
else
{
_SetHPTimerAfterNow(MASTER_DELAY_SPACE,master_send_bit,master_send_bit,0);
}
}
edit: another question, I have the bitwise operator
master_message_buffer & (1 << master_bit_number) used to extract the bit I want to send, it would be correct to have master_bit_number set to 0 to read the first bit right?