writing merged USB comm code

Now that I have USB receive working in the main PC code, its time to merge the USB transmit(and receive for commands) into the main SX code.

I have two pseudo-code versions written.

1> First version uses the ISR to handle communication.  It switches between different ‘modes’ ala my last post.  It is pretty complicated with different modes for different states, and I think troubleshooting it could be a pain in the butt.  Uses interrupts for each bit that needs transmitted and received.

2> I like the second version I just wrote because it can be used inside MAIN and doesn’t depend upon interrupts at all.  This means that the code that receives the data remains untouched and (hopefully) working.  The drive-receive code is entirely ISR, and so this makes sense to me.  I’ll have to temporarily disable falling-edge detection, so that a spurious bit doesn’t trigger the ISR in the middle.  Now the downside to this is that I have no-op delays between sections of code.  There are literally 80-some no’ops between the send and receive code.

I think I can optimize #2, certainly.  Have some loops perhaps.  I’m going to look online to see if I can find some convenient delay code.  I have to delay roughly 500ns between bits.

I’m hoping this new code fixes the speed problem I was seeing earlier, we’ll see soon enough.

 

About the author

keith

Amateur Electronics Design Engineer and Hacker

One Comment