Hi Ron,
I analyzed your code. The function could be written in a better way, but If you use while ((CAN_0.IFLAG1.B.BUF0I & 1) == 0) {} in for loop, it should works correct. But you do not set some important fields in MB such as length of the frame, used ID and other. And because the MBs are placed in RAM memory, there should be some random data, which can cause problems.
Look at the following source code and set it in the same way except of data bytes.
CAN_0.MB[0].CS.B.CODE = 0x8; //MB TX inactive
CAN_0.MB[0].ID.B.ID_STD = 0; //set message STD ID
CAN_0.MB[0].DATA.W[1] = 0xAABBCCDD; //data1 set
CAN_0.MB[0].DATA.W[0] = 0x12345678; //data0 set
CAN_0.MB[0].CS.B.DLC = 8; //message length 8 bytes
CAN_0.MB[0].CS.B.RTR = 0; //remote frame disable
CAN_0.MB[0].CS.B.IDE = 0; //extended bit disable
CAN_0.MB[0].CS.B.SRR = 0; //not used with STD_ID
CAN_0.MB[0].CS.B.CODE = 0xC; //MB once transmit dat
From my point of view, it is better to use 4 MBs instead of one. Then you do not have to wait until data are sent.
Regards,
Martin