Ch552 sdcc callback passing values

I am using a simple midi library for ch55x boards. Midi out works fine, but midi in doesn’t.
The library correctly handles the incoming message, but things go wrong (empty values) when data is passed on to the callback function.

In the sketch I have:

void onNoteOn(__xdata uint8_t ch, __xdata uint8_t note, __xdata uint8_t vel) {
  sendNoteOn(ch,note,vel);  // loopback
  USBSerial_println("onNoteOn");
}

With the callback registered in setup:
setHdlNoteOn(onNoteOn);

The library has:

hdlMidiMessage cbNoteOn;
hdlNoteOff cbNoteOff;
hdlMidiMessage cbCtlChange;
void setHdlNoteOn(hdlMidiMessage pfunc){
  cbNoteOn = pfunc;
}
void processMidiMessage(){
  uint8_t cnt, kindmessage;
  uint8_t len = USBMIDIAvailable();
  uint8_t *p;

  if(len > 0){
    memcpy(rcvBuffer,Ep2Buffer+32,USBByteCountEP3);
    rcvIndex = 0;
    rcvLength = USBByteCountEP3;
    UEP3_CTRL = UEP3_CTRL & ~ MASK_UEP_R_RES | UEP_R_RES_ACK;
    USBByteCountEP3 = 0;
    for(cnt=0;cnt<rcvLength;cnt+=4){
      p = (uint8_t *)(rcvBuffer + cnt);
      kindmessage = checkMidiMessage(p);
      if(kindmessage == 1){
        if(cbNoteOff != NULL){
          (*cbNoteOff)(*(p+1)&0x0f,*(p+2)&0x7f);
        }
      }else if(kindmessage == 2){
        if(cbNoteOn != NULL){
          (*cbNoteOn)(*(p+1)&0x0f,*(p+2)&0x7f,*(p+3)&0x7f);
        }
      }else if(kindmessage == 3){
        if(cbCtlChange != NULL){
          (*cbCtlChange)(*(p+1)&0x0f,*(p+2)&0x7f,*(p+3)&0x7f);
        }
      }
    }
  }
}

The data is present in processMidiMessage (both in rcvMessage and p, just before handin stuff over to
(*cbNoteOn)(*(p+1)&0x0f,*(p+2)&0x7f,*(p+3)&0x7f);

Ch, note and vel are zero when the callback is reached in the sketch.
I have searched extensively, gotten co-pilot to help me etc, but this is a mix of pointers, sdcc, weird mcs51 memorymap that goes beyond my capabilities. Can anybody help me out?

Hello, do yourself a favour and please read How to get the best out of this forum and post accordingly (including code with code tags and necessary documentation for your ask like your exact circuit and power supply, links to components etc).


Please correct your post and add code tags around your code.

There is a small pencil image below your existing posts.

  • click on this pencil ➜ that will let you edit your post.
  • Select the part of the text that corresponds to the code
  • Click on the <code/> icon in the toolbar to indicate that it is code
  • click image Save Edit

(Also make sure to properly indent the code in the IDE before copying and pasting it here. This can be done by pressing ctrlT on a PC or cmdT on a Mac)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.