Buriedcode
Full Member level 6
php empty serial buffer
Hi,
I'm designing a MIDI controller (keyboard) with 49 switches. Using a PIC's 'serial port' (USART). Whilst writing the code, I suddenly thought, how am I going to send multiple messages? MIDI requires that, for, say, a 'note-on' message, 3 bytes are sent, consecutively (one after the other). But of course, it takes time to send a byte, and I cannot wait for the buffer to be empty, the PIC needs to be doing other things.
Thats ok, but if I'm in the middle of sending a message (3 bytes total), and more data comes from the keyboard, whilst scanning, where do I put this new data?
So, I thought, if I have an interupt, that pings when the SBUFF is empty (data sending/sent) I could have a small subroutine, that loads in the next byte to be sent so there are no gaps between the 3 bytes. Thats ok, but in this subroutine, I'm sure I would need multiple 'buffer' registers, to store data to be sent, ie: a FIFO buffer. Short of moving contents of registers up the buffer, I don't really know what to do.
I imagine a clever use of interupts and timers is needed, so that I do not miss any information coming from the keyboard, or start dropping messages. I also want to keep latency down.
Just wondering if anyone knew some tricks for this.
confused,
BuriedCOde.
Hi,
I'm designing a MIDI controller (keyboard) with 49 switches. Using a PIC's 'serial port' (USART). Whilst writing the code, I suddenly thought, how am I going to send multiple messages? MIDI requires that, for, say, a 'note-on' message, 3 bytes are sent, consecutively (one after the other). But of course, it takes time to send a byte, and I cannot wait for the buffer to be empty, the PIC needs to be doing other things.
Thats ok, but if I'm in the middle of sending a message (3 bytes total), and more data comes from the keyboard, whilst scanning, where do I put this new data?
So, I thought, if I have an interupt, that pings when the SBUFF is empty (data sending/sent) I could have a small subroutine, that loads in the next byte to be sent so there are no gaps between the 3 bytes. Thats ok, but in this subroutine, I'm sure I would need multiple 'buffer' registers, to store data to be sent, ie: a FIFO buffer. Short of moving contents of registers up the buffer, I don't really know what to do.
I imagine a clever use of interupts and timers is needed, so that I do not miss any information coming from the keyboard, or start dropping messages. I also want to keep latency down.
Just wondering if anyone knew some tricks for this.
confused,
BuriedCOde.