实验现象

image.png
image.png
LIN控制子系统
image.png

代码

ASCLIN_LIN_Master.c

07ASCLIN-LIN - 图4

  1. /*********************************************************************************************************************/
  2. /*-----------------------------------------------------Includes------------------------------------------------------*/
  3. /*********************************************************************************************************************/
  4. #include "IfxAsclin.h"
  5. #include "IfxAsclin_Lin.h"
  6. #include "ASCLIN_LIN_Master.h"
  7. /*********************************************************************************************************************/
  8. /*------------------------------------------------------Macros-------------------------------------------------------*/
  9. /*********************************************************************************************************************/
  10. #define SERIAL_BAUDRATE 19200 /* Set the baud rate */
  11. #define SIZE 12 /* Size of the message */
  12. #define ID_BYTE 0x80 /* Set the LIN ID byte to a random number */
  13. #define RX_PIN IfxAsclin1_RXB_P15_5_IN /* Set RX port pin */
  14. #define TX_PIN IfxAsclin1_TX_P15_5_OUT /* Set TX port pin */
  15. /*********************************************************************************************************************/
  16. /*-------------------------------------------------Global variables--------------------------------------------------*/
  17. /*********************************************************************************************************************/
  18. static IfxAsclin_Lin g_linMaster;
  19. /*********************************************************************************************************************/
  20. /*----------------------------------------------Function Implementations---------------------------------------------*/
  21. /*********************************************************************************************************************/
  22. /* This function initializes the ASCLIN LIN module in master mode */
  23. void init_ASCLIN_LIN_master(void)
  24. {
  25. /* Initialize one instance of IfxAsclin_Lin_Config with default values */
  26. IfxAsclin_Lin_Config linMasterConfig;
  27. IfxAsclin_Lin_initModuleConfig(&linMasterConfig, &MODULE_ASCLIN1);
  28. linMasterConfig.linMode = IfxAsclin_LinMode_master; /* Set the LIN mode of operation */
  29. linMasterConfig.brg.baudrate = SERIAL_BAUDRATE; /* Set the desired baud rate */
  30. const IfxAsclin_Lin_Pins pins =
  31. {
  32. &RX_PIN, IfxPort_InputMode_pullUp, /* RX port pin */
  33. &TX_PIN, IfxPort_OutputMode_pushPull, /* TX port pin */
  34. IfxPort_PadDriver_cmosAutomotiveSpeed1
  35. };
  36. linMasterConfig.pins = &pins; /* Port pins configuration */
  37. /* Initialize module */
  38. IfxAsclin_Lin_initModule(&g_linMaster, &linMasterConfig);
  39. }
  40. /* This function sends the string "Hello World!" */
  41. void send_ASCLIN_LIN_message(void)
  42. {
  43. uint8 txId = ID_BYTE; /* ID which gets transmitted within the header */
  44. uint8 txData[SIZE] = {"Hello World!"}; /* Frame to send */
  45. /* After the transmission of the LIN header by the master, the master itself starts the transmission
  46. * of the message.
  47. */
  48. IfxAsclin_Lin_sendHeader(&g_linMaster, &txId); /* Send LIN header */
  49. if(g_linMaster.acknowledgmentFlags.txHeaderEnd == 1) /* If the LIN header has been transmitted */
  50. {
  51. IfxAsclin_Lin_sendResponse(&g_linMaster, txData, SIZE); /* Send message */
  52. }
  53. }