Pertaining to the HCS12 Tx problem post of yesterday, thanks to all who have reverted, but I've become completely stuck. If I attempt to send two chars by calling SendMIDI twice, nothing comes out. Hardware is fine, and a simple polled output routine works OK. Plenty of stack space, arrays and variables are all correctly declared and initialised, can't see anything else that could cause a problem.
I'm attempting to trace through the IRQ using polled serial writes to another COM port, it confirms that the ISR is triggering but I think the trace writes might be messing up the timing and the result may not be trustworthy. If anyone can see anything obviously wrong in the following, it would be appreciated. TIA
int SendMIDI (char c) { char d ; d = SCI1SR1 ; // SCI status register if ((d & TDRE) != 0) /* register is free, send immediately */ { SCI1DRL = c ; return 0 ; }
/* Transmitter is busy, queue data */ DisableInts ; mobuf[midoxi++] = c ; if (midoxi > 89) midoxi = 0 ; // wrap buffer round SCI1CR2 |= TIE ; // Data queued, enable Tx interrupt EnableInts ; return 1 ; }
// MIDI send interrupt handler. #pragma interrupt_handler MIDI_handler
void MIDI_handler(void) { char c, d ; c = SCI1SR1 ; // SIO status reg
if ((c & TDRE) == 0) return ; // buffer hasn't cleared yet, have to wait
// Here the Tx buffer is empty. if (midoxi == midoxo) return ; // No queued data
SCI1DRL = mobuf[midoxo++] ; send next queued byte & wrap buffer index if (midoxo > 89) midoxo = 0 ;
if (midoxo == midoxi) SCI1CR2 &= (~TIE) ; // buffer cleared, Mask Tx IRQ }