Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(void)
- {
- _disable_interrupts();
- SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
- while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF));
- HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; //Unlock GPIO_CR register with this magic value
- HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = 0xFF;
- GPIOPinConfigure(GPIO_PF0_CAN0RX);
- GPIOPinConfigure(GPIO_PF3_CAN0TX);
- GPIOPinTypeCAN(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_3);
- SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
- while(!SysCtlPeripheralReady(SYSCTL_PERIPH_CAN0));
- CANInit(CAN0_BASE);
- CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 500000);
- CANEnable(CAN0_BASE);
- CANRetrySet(CAN0_BASE, false);
- tCANMsgObject sCANMessage;
- uint8_t can_msg_contents[8];
- can_msg_contents[0] = 0U;
- sCANMessage.ui32MsgIDMask = 0xF; // Do we need this for TX objects?? We'll find out :)
- sCANMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE;
- sCANMessage.ui32MsgLen = 1;
- sCANMessage.pui8MsgData = can_msg_contents;
- sCANMessage.ui32MsgID = 0x60000003;
- CANMessageSet(CAN0_BASE, 2, &sCANMessage, MSG_OBJ_TYPE_TX);
- // while ((CANStatusGet(CAN0_BASE, CAN_STS_CONTROL)&CAN_STS_TXOK)==0);
- uint32_t stat = HWREG(CAN0_BASE + CAN_O_STS);
- while(stat & CAN_STS_TXOK == 0)
- {
- stat = HWREG(CAN0_BASE + CAN_O_STS);
- }
- HWREG(CAN0_BASE + CAN_O_STS) = ~(CAN_STS_RXOK | CAN_STS_TXOK |
- CAN_STS_LEC_M);
- while(1)
- {
- ++can_msg_contents[0];
- CANMessageSet(CAN0_BASE, 2, &sCANMessage, MSG_OBJ_TYPE_TX);
- // while ((CANStatusGet(CAN0_BASE, CAN_STS_CONTROL)&CAN_STS_TXOK)==0);
- stat = HWREG(CAN0_BASE + CAN_O_STS);
- while(stat & CAN_STS_TXOK == 0)
- {
- stat = HWREG(CAN0_BASE + CAN_O_STS);
- }
- HWREG(CAN0_BASE + CAN_O_STS) = ~(CAN_STS_RXOK | CAN_STS_TXOK |
- CAN_STS_LEC_M);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement