Hello,
I try to bootload F28335 through eCAN and load my application code into flash of F28335 and I found an example code for this purpose . But, I could not receive data through eCAN by polling method.
CPU waits on this line :
while(ECanaRegs.CANRMP.all == 0) { }
Function that receives data through CAN is :
Uint16 CAN_GetWordData()
{
Uint16 wordData;
Uint16 byteData;
wordData = 0x0000;
byteData = 0x0000;
// Fetch the LSB
while(ECanaRegs.CANRMP.all == 0) { }
wordData = (Uint16) ECanaMboxes.MBOX1.MDL.byte.BYTE0; // LS byte
// Fetch the MSB
byteData = (Uint16)ECanaMboxes.MBOX1.MDL.byte.BYTE1; // MS byte
// form the wordData from the MSB:LSB
wordData |= (byteData << 8);
/* Clear all RMPn bits */
ECanaRegs.CANRMP.all = 0xFFFFFFFF;
return wordData;
}
CAN initialization function :
void CAN_Init()
{
/* Create a shadow register structure for the CAN control registers. This is
needed, since only 32-bit access is allowed to these registers. 16-bit access
to these registers could potentially corrupt the register contents or return
false data. This is especially true while writing to/reading from a bit
(or group of bits) among bits 16 - 31 */
struct ECAN_REGS ECanaShadow;
EALLOW;
/* Enable CAN clock */
SysCtrlRegs.PCLKCR0.bit.ECANAENCLK=1;
/* Configure eCAN-A pins using GPIO regs*/
GpioCtrlRegs.GPAMUX2.bit.GPIO30 = 1; // GPIO30 is CANRXA
GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 1; // GPIO31 is CANTXA
/* Enable internal pullups for the CAN pins */
GpioCtrlRegs.GPAPUD.bit.GPIO30 = 0;
GpioCtrlRegs.GPAPUD.bit.GPIO31 = 0;
/* Asynch Qual */
GpioCtrlRegs.GPAQSEL2.bit.GPIO30 = 3;
/* Configure eCAN RX and TX pins for CAN operation using eCAN regs*/
ECanaShadow.CANTIOC.all = ECanaRegs.CANTIOC.all;
ECanaShadow.CANTIOC.bit.TXFUNC = 1;
ECanaRegs.CANTIOC.all = ECanaShadow.CANTIOC.all;
ECanaShadow.CANRIOC.all = ECanaRegs.CANRIOC.all;
ECanaShadow.CANRIOC.bit.RXFUNC = 1;
ECanaRegs.CANRIOC.all = ECanaShadow.CANRIOC.all;
/* Initialize all bits of 'Message Control Register' to zero */
// Some bits of MSGCTRL register come up in an unknown state. For proper operation,
// all bits (including reserved bits) of MSGCTRL must be initialized to zero
ECanaMboxes.MBOX1.MSGCTRL.all = 0x00000000;
/* Clear all RMPn, GIFn bits */
// RMPn, GIFn bits are zero upon reset and are cleared again as a precaution.
ECanaRegs.CANRMP.all = 0xFFFFFFFF;
/* Clear all interrupt flag bits */
ECanaRegs.CANGIF0.all = 0xFFFFFFFF;
ECanaRegs.CANGIF1.all = 0xFFFFFFFF;
/* Configure bit timing parameters for eCANA*/
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.CCR = 1 ; // Set CCR = 1
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
ECanaShadow.CANES.all = ECanaRegs.CANES.all;
do
{
ECanaShadow.CANES.all = ECanaRegs.CANES.all;
} while(ECanaShadow.CANES.bit.CCE != 1 ); // Wait for CCE bit to be set..
ECanaShadow.CANBTC.all = 0;
ECanaShadow.CANBTC.bit.BRPREG = 0;
ECanaShadow.CANBTC.bit.TSEG2REG = 2;
ECanaShadow.CANBTC.bit.TSEG1REG = 10;
ECanaShadow.CANBTC.bit.SAM = 1;
ECanaRegs.CANBTC.all = ECanaShadow.CANBTC.all;
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.CCR = 0 ; // Set CCR = 0
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
ECanaShadow.CANES.all = ECanaRegs.CANES.all;
do
{
ECanaShadow.CANES.all = ECanaRegs.CANES.all;
} while(ECanaShadow.CANES.bit.CCE != 0 ); // Wait for CCE bit to be cleared..
/* Disable all Mailboxes */
ECanaRegs.CANME.all = 0; // Required before writing the MSGIDs
/* Assign MSGID to MBOX1 */
ECanaMboxes.MBOX1.MSGID.all = 0x00040000; // Standard ID of 1, Acceptance mask disabled
/* Configure MBOX1 to be a receive MBOX */
ECanaRegs.CANMD.all = 0x0002;
/* Enable MBOX1 */
ECanaRegs.CANME.all = 0x0002;
EDIS;
return;
}
so What is my fault ? Any help will be appreciated.
Thanks in advance
Sertac