Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

quick question about serial buffer..

Status
Not open for further replies.

Buriedcode

Full Member level 6
Joined
May 6, 2004
Messages
357
Helped
43
Reputation
86
Reaction score
7
Trophy points
1,298
Location
London
Activity points
8,887
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.
 

The ring buffer seems to be just for you. You need to know the head location, the length of the buffer and the contents counter. one process loads the buffer, and the UART process sends characters from that buffer if it is not empty.
The length of the buffer should be big enough to accomodate all your messages.
 

    Buriedcode

    Points: 2
    Helpful Answer Positive Rating
yego,

Thankyou for your reply! Very helpful.
I have heard of a 'ring buffer' before, back in uni, but I've never implemented one, so I reading up on it on the net and using some books I have. Exactly what you said, just right for my application, I don't think I have a real limit on its size (obviously some limit, since this PIC has finite memory) because my main code is actually quite small, and only uses about 20 registers. I think the buffer size, at maximum would only need to be maybe 20 registers, probably 12.

I'm attempting to implement one now, trying to get latency down, and to make it as small as efficient as possible (can be quite difficult in assembly, but worth it). The fact that the PIC I have has interupts coming out of its ears is helpful too :)

Thanks again bro,

BuriedCode
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top