SX/B serin command
jwillis
Posts: 8
I have designed a MIDI decoder board based on the SX-28 programed in SX/B.· The SX recieves a MIDI data stream at 31500 baud 8 data bits 1 stop bit using SERIN,·processes··each byte of the 3 byte message as they arrive,·and with some processing decodes the note on and off information and enables or disables a bit in an external 64 bit register to drive organ pipes.
The system works well as long as there is a slight pause between bytes (1 bit length)·to allow for processing. ·My keyboard encoders are based on the basic stamp 2-SX, and thus the 3·bytes of the midi message·are slightly separated using SEROUT. ·Midi·messages from a computer, however, come out as a continuous 3 byte·data stream without pause except for the stop bit of each byte.· The SX cannot seem to ·keep up using SERIN·and data is·lost causing chaos at the output drivers.
I cannot easily change the UART parameters in the computer to add another stop bit.· Can SERIN be used in this circumstance, or will it be necessary to go to an interrupt driven·UART subroutine?
Thanks
Jwillis
·
The system works well as long as there is a slight pause between bytes (1 bit length)·to allow for processing. ·My keyboard encoders are based on the basic stamp 2-SX, and thus the 3·bytes of the midi message·are slightly separated using SEROUT. ·Midi·messages from a computer, however, come out as a continuous 3 byte·data stream without pause except for the stop bit of each byte.· The SX cannot seem to ·keep up using SERIN·and data is·lost causing chaos at the output drivers.
I cannot easily change the UART parameters in the computer to add another stop bit.· Can SERIN be used in this circumstance, or will it be necessary to go to an interrupt driven·UART subroutine?
Thanks
Jwillis
·
Comments
What clock speed are you running the SX at ?
You can try a faster clock speed to see if that helps.
If not, an interrupt receive routine would be best.
I think Jon Williams is working on some midi stuff with the SX. Maybe he'll chime in.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video Display Module" Available Now.
www.sxvm.com
"Great people talk about great things, average people talk about average things, small people talk about other people."
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
トヨタは すばらし です!!
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video Display Module" Available Now.
www.sxvm.com
"Great people talk about great things, average people talk about average things, small people talk about other people."
·
In my applications, I don't process anything "between" the bytes (except checking for new status bytes to handle running status), i.e. I first receive all bytes to complete a MIDI message into a buffer, and then do the necessary processing. The processing code always reads the three buffered message bytes, i.e. it does not "know" about running status.
Instead, this is handled by the receive routine filling that buffer. IOW - when a byte is received with bit 7 set, this is assumed to be a new status byte to be copied into the first byte of the buffer (byte 0). Next, two more bytes are read and copied into the buffer (bytes 1 and 2). If the receive routine gets the first byte with bit 7 clear, it assumes running status, saves this in byte 1 of the buffer, and expects just one more byte to be saved in byte 2 of the buffer, leaving byte 0 (the status) unchanged.
MIDI data comes in at 31,250 Baud, i.e. the bit period is 32 µs. With an SX clocked at 50 MHz, instruction cycles take 20 ns which means that you can execute "tons" of instructions between two ISR calls to handle the MIDI UART code, and I never had a problem with this.
It is important though, that you don't call a routine for receiving a byte putting the mainline program on hold until the complete byte has been received. Instead, the UART receive code in the ISR should set an "RX_Avail" flag when it has received a new byte. After having processed the previously received byte, the mainline program should enter into a loop waiting until the ISR has set this flag, clear it, and then process the new byte while the ISR code takes care of receiving the next one.
This way, you should have more than enough processing time in the mainline program.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
Günther
Is your UART subroutine based on periodic interrupts by the RTC to allow other processing to go on while waiting to sample the serial data stream?
Jim
yes, the UART code is executed in an interrupt service routine, periodically called on RTCC roll-overs. This is the "classical" UART Virtual Peripheral for the SX, available from various resources. When you download www.parallax.com/dl/src/prod/sx/ProgSXEdPre.zip which contains the source codes published in my book, you can find the UART code in TUT040.SRC.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
Jon has code posted in the "Projects" forum. Look for "MIDI Receiver with SX/B".
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video Display Module" Available Now.
www.sxvm.com
"It's not getting what you want, it's wanting what you've got."
·
I'll let all of you know how this comes out. When I have it working I will post the code. I also have a circuit board layout using express.pcb which I will also post when everything is working.
Thanks
Jim Willis
BTW for 31,250 Baud (MIDI), the constants in TUT040.SRC should be defined as follows:
baud_bit = 3
start_delay = 13
int_period = 200
Good Luck!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
Could you give me an example of the SX-B code to test the rx_flag and obtain the rx_byte?
Thanks
Jim Willis