Advertisement
Guest User

Untitled

a guest
Feb 13th, 2017
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. int main(void)
  2. {
  3. _disable_interrupts();
  4.  
  5. SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
  6.  
  7. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  8. while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF));
  9. HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; //Unlock GPIO_CR register with this magic value
  10. HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = 0xFF;
  11.  
  12. GPIOPinConfigure(GPIO_PF0_CAN0RX);
  13. GPIOPinConfigure(GPIO_PF3_CAN0TX);
  14. GPIOPinTypeCAN(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_3);
  15.  
  16. SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
  17. while(!SysCtlPeripheralReady(SYSCTL_PERIPH_CAN0));
  18. CANInit(CAN0_BASE);
  19. CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 500000);
  20. CANEnable(CAN0_BASE);
  21. CANRetrySet(CAN0_BASE, false);
  22.  
  23. tCANMsgObject sCANMessage;
  24. uint8_t can_msg_contents[8];
  25. can_msg_contents[0] = 0U;
  26.  
  27. sCANMessage.ui32MsgIDMask = 0xF; // Do we need this for TX objects?? We'll find out :)
  28. sCANMessage.ui32Flags = MSG_OBJ_TX_INT_ENABLE;
  29. sCANMessage.ui32MsgLen = 1;
  30. sCANMessage.pui8MsgData = can_msg_contents;
  31. sCANMessage.ui32MsgID = 0x60000003;
  32.  
  33. CANMessageSet(CAN0_BASE, 2, &sCANMessage, MSG_OBJ_TYPE_TX);
  34. // while ((CANStatusGet(CAN0_BASE, CAN_STS_CONTROL)&CAN_STS_TXOK)==0);
  35. uint32_t stat = HWREG(CAN0_BASE + CAN_O_STS);
  36. while(stat & CAN_STS_TXOK == 0)
  37. {
  38. stat = HWREG(CAN0_BASE + CAN_O_STS);
  39. }
  40. HWREG(CAN0_BASE + CAN_O_STS) = ~(CAN_STS_RXOK | CAN_STS_TXOK |
  41. CAN_STS_LEC_M);
  42.  
  43. while(1)
  44. {
  45. ++can_msg_contents[0];
  46. CANMessageSet(CAN0_BASE, 2, &sCANMessage, MSG_OBJ_TYPE_TX);
  47. // while ((CANStatusGet(CAN0_BASE, CAN_STS_CONTROL)&CAN_STS_TXOK)==0);
  48. stat = HWREG(CAN0_BASE + CAN_O_STS);
  49. while(stat & CAN_STS_TXOK == 0)
  50. {
  51. stat = HWREG(CAN0_BASE + CAN_O_STS);
  52. }
  53. HWREG(CAN0_BASE + CAN_O_STS) = ~(CAN_STS_RXOK | CAN_STS_TXOK |
  54. CAN_STS_LEC_M);
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement