Wurlitzer
01-31-2008, 04:58 AM
I used an object from the forum for MIDI and I was only interested in the bit bang serial input code.
I kept (I thought) intact, the original code for building the midiByte but it seems like most serial communications with micros I get garbage.
Using a standard MIDI Keyboard sending single Note On/Off messages I should be building a·long of HEX: 00_90_0C_(40 or 00)
What I get is 3 bytes but nothing close to what I expect. Almost like the baud rate is wrong. Byte #2 of this long seems to be $FF more often than not when it should be $90. Bytes 1,0 make no sense at all.
I am using a Crystal and have set the clock as follows:
_clkmode······· = xtal1 + pll16x
·_xinfreq······· = 5_000_000
Also, the circular queue tail pointer does not always increment with each message making me think the baud rate calculation is wrong. 31,250 is the standard MIDI baud rate.
NOTE: I just edited the mov midiBits, #8 to read mov midiBits, #9 and the: ·shr···· midiByte,#32-8 to shr···· midiByte,#32-9
PUB start(_midiPin, _Ptr_HubRamStartAddr): okay '_Ptr_HubRamStartAddr contains the starting address of array in hub
tmpCog :=cogid
midiPin := _midiPin ' Move the SPIN parameters to the DAT section
bitticks := clkfreq / 31_250 ' command.
halfticks := bitticks / 2
okay := cog := cognew(@entry3, _Ptr_HubRamStartAddr) + 1
DAT
''************************************************
''* Assembly language MIDI serial driver/decoder *
''************************************************
org
entry3
getMidiByte waitpne midiMask,midiPin ' Wait for a start bit.
mov midiBits,#9 ' Set the number of bits
mov bitClk,cnt ' and initialize
add bitClk,halfticks ' the clock to the
add bitClk,bitticks ' middle of the first bit
:midiBit waitcnt bitClk,bitticks ' Wait until the bit is there
test midiMask,ina wc ' Receive bit on the MIDI in pin,
rcr midiByte,#1
' rotate it into our MIDI byte
djnz midiBits,#:midiBit ' and go get the next bit
shr midiByte,#32-9 ' Justify and trim the received
and midiByte,#$FF ' MIDI byte
'After this code, I just collect 3 bytes then write them as a long into a circular Queue with the 8 MSbits=0.
Post Edited (Wurlitzer) : 1/30/2008 10:06:11 PM GMT
I kept (I thought) intact, the original code for building the midiByte but it seems like most serial communications with micros I get garbage.
Using a standard MIDI Keyboard sending single Note On/Off messages I should be building a·long of HEX: 00_90_0C_(40 or 00)
What I get is 3 bytes but nothing close to what I expect. Almost like the baud rate is wrong. Byte #2 of this long seems to be $FF more often than not when it should be $90. Bytes 1,0 make no sense at all.
I am using a Crystal and have set the clock as follows:
_clkmode······· = xtal1 + pll16x
·_xinfreq······· = 5_000_000
Also, the circular queue tail pointer does not always increment with each message making me think the baud rate calculation is wrong. 31,250 is the standard MIDI baud rate.
NOTE: I just edited the mov midiBits, #8 to read mov midiBits, #9 and the: ·shr···· midiByte,#32-8 to shr···· midiByte,#32-9
PUB start(_midiPin, _Ptr_HubRamStartAddr): okay '_Ptr_HubRamStartAddr contains the starting address of array in hub
tmpCog :=cogid
midiPin := _midiPin ' Move the SPIN parameters to the DAT section
bitticks := clkfreq / 31_250 ' command.
halfticks := bitticks / 2
okay := cog := cognew(@entry3, _Ptr_HubRamStartAddr) + 1
DAT
''************************************************
''* Assembly language MIDI serial driver/decoder *
''************************************************
org
entry3
getMidiByte waitpne midiMask,midiPin ' Wait for a start bit.
mov midiBits,#9 ' Set the number of bits
mov bitClk,cnt ' and initialize
add bitClk,halfticks ' the clock to the
add bitClk,bitticks ' middle of the first bit
:midiBit waitcnt bitClk,bitticks ' Wait until the bit is there
test midiMask,ina wc ' Receive bit on the MIDI in pin,
rcr midiByte,#1
' rotate it into our MIDI byte
djnz midiBits,#:midiBit ' and go get the next bit
shr midiByte,#32-9 ' Justify and trim the received
and midiByte,#$FF ' MIDI byte
'After this code, I just collect 3 bytes then write them as a long into a circular Queue with the 8 MSbits=0.
Post Edited (Wurlitzer) : 1/30/2008 10:06:11 PM GMT