This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

problem with transfer parameter into subroutine

I am having some problem to pass parameter into subroutine.

I have defined:

BOOLEAN CRC_Message_Verify(UINT8 nbyte);

in my program, I have this line:

crc_ok = CRC_Message_Verify(SpiLoadIndex);

in which, SpiLoadIndex is defined as UINT8 xdata type,

when I single step debugging, before calling CRC_Message_Verify function, SpiLoadIndex = 5, and inside the subroutine, nbyte = 95. How come nbyte is totally different? Any ideas?

Parents
  • I use send/receive buffer for serial command handler, but like I said it is different for SPI case. When master processor query data through SPI, my C51 need to have the data ready. If I use send/receive buffer for SPI, that just means I have to put more delay to query each byte of data, which is not desired for my application.

    I do use mini state machine for this SPI ISR routine right now. It is kind complicated error checking/hand shaking processing, but I am still not comfortable with the long term reliability.

    Your idea on CRC calculated by byte is an excellent one. I will change to that, and maybe if I break my CRC routine into this big ISR instead of calling it as a subroutine at the end can eliminate my problem.
    thanks,

Reply
  • I use send/receive buffer for serial command handler, but like I said it is different for SPI case. When master processor query data through SPI, my C51 need to have the data ready. If I use send/receive buffer for SPI, that just means I have to put more delay to query each byte of data, which is not desired for my application.

    I do use mini state machine for this SPI ISR routine right now. It is kind complicated error checking/hand shaking processing, but I am still not comfortable with the long term reliability.

    Your idea on CRC calculated by byte is an excellent one. I will change to that, and maybe if I break my CRC routine into this big ISR instead of calling it as a subroutine at the end can eliminate my problem.
    thanks,

Children
  • Just to close the issue. The problem is caused by the size of my data. The data memory of this chip is 2k. My original way of designing SPI command structure is to include everything into one structure. And the command array is fairly big, so my data is bigger than 2k. The compiler did not complain, but I think they just overwrite each other during my debug session.

    I solved the problem by separating command structure into several structures, some of them can be set as constant and reside in code space.

    Thank you all for the help.