{"id":3276,"date":"2025-03-08T09:08:28","date_gmt":"2025-03-08T09:08:28","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=3276"},"modified":"2025-03-09T13:35:24","modified_gmt":"2025-03-09T13:35:24","slug":"getting-started-with-lin-local-interconnected-network-part-1-sending-data","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=3276","title":{"rendered":"Getting Started with LIN (Local Interconnected Network) Part 2: Sending Data"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-01-16.00.55-A-cover-image-for-a-technical-guide-on-LIN-Local-Interconnect-Network-bus-using-STM32F4.-The-image-should-feature-an-STM32F4-microcontroller-with-hi-1.webp\" alt=\"\" class=\"wp-image-3277\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-01-16.00.55-A-cover-image-for-a-technical-guide-on-LIN-Local-Interconnect-Network-bus-using-STM32F4.-The-image-should-feature-an-STM32F4-microcontroller-with-hi-1.webp 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-01-16.00.55-A-cover-image-for-a-technical-guide-on-LIN-Local-Interconnect-Network-bus-using-STM32F4.-The-image-should-feature-an-STM32F4-microcontroller-with-hi-1-300x300.webp 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-01-16.00.55-A-cover-image-for-a-technical-guide-on-LIN-Local-Interconnect-Network-bus-using-STM32F4.-The-image-should-feature-an-STM32F4-microcontroller-with-hi-1-150x150.webp 150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-01-16.00.55-A-cover-image-for-a-technical-guide-on-LIN-Local-Interconnect-Network-bus-using-STM32F4.-The-image-should-feature-an-STM32F4-microcontroller-with-hi-1-768x768.webp 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-01-16.00.55-A-cover-image-for-a-technical-guide-on-LIN-Local-Interconnect-Network-bus-using-STM32F4.-The-image-should-feature-an-STM32F4-microcontroller-with-hi-1-750x750.webp 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-01-16.00.55-A-cover-image-for-a-technical-guide-on-LIN-Local-Interconnect-Network-bus-using-STM32F4.-The-image-should-feature-an-STM32F4-microcontroller-with-hi-1-400x400.webp 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/DALL\u00b7E-2025-03-01-16.00.55-A-cover-image-for-a-technical-guide-on-LIN-Local-Interconnect-Network-bus-using-STM32F4.-The-image-should-feature-an-STM32F4-microcontroller-with-hi-1-250x250.webp 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In part 2 of LIN guide, we shall start transmitting data over LIN bus and decode them using either oscilloscope or logic analyzer.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Creating source and header files.<\/li>\n\n\n\n<li>Developing the header file.<\/li>\n\n\n\n<li>Developing the source file.<\/li>\n\n\n\n<li>Logic Analyzer connection<\/li>\n\n\n\n<li>Testing the driver.<\/li>\n\n\n\n<li>Results.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Creating Source and Header Files:<\/h2>\n\n\n\n<p>After the project has been generated, right click on src folder and add new source file as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"692\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-27-02-1024x692.jpg\" alt=\"\" class=\"wp-image-3278\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-27-02-1024x692.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-27-02-300x203.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-27-02-768x519.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-27-02-1536x1037.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-27-02-2048x1383.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-27-02-1150x777.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-27-02-750x507.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-27-02-400x270.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-27-02-250x169.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Name the source file as LIN.c as following (here, it is already created):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"734\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-28-05-1024x734.jpg\" alt=\"\" class=\"wp-image-3279\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-28-05-1024x734.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-28-05-300x215.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-28-05-768x550.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-28-05-1150x824.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-28-05-750x538.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-28-05-400x287.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-28-05-250x179.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-28-05.jpg 1172w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In similar manner, the create new header file with name of LIN.h<\/p>\n\n\n\n<p>Thats all for creating header and source file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Developing the Header File:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>In the header file, include the required header files as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;main.h&quot;\n#include &quot;stdint.h&quot;<\/pre><\/div>\n\n\n\n<p>Declare the following function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">uint8_t LIN_Transmit_Data(uint8_t ID, uint8_t *data, uint16_t len);<\/pre><\/div>\n\n\n\n<p>The function shall transmit data over LIN bus.<\/p>\n\n\n\n<p>The function shall take the following parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>ID which is the identification of the node that shall receive the message.<\/li>\n\n\n\n<li>Pointer of the data to be transmitted.<\/li>\n\n\n\n<li>Length of the data to be transmitted.<\/li>\n<\/ul>\n\n\n\n<p>The function shall return 0 in case of success and -1 in case of failure.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Thats all for the header file.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Developing the Source File:<\/h2>\n\n\n\n<p><br>Next, open LIN.c source file.<\/p>\n\n\n\n<p>We start by including the following headers file:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;LIN.h&quot;\n#include &quot;usart.h&quot;<\/pre><\/div>\n\n\n\n<p>Then we shall declare the following function to calculate the check sum of the message as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">static uint8_t checksum_Calc (uint8_t PID, uint8_t *data, int size)\n{\n\tuint8_t buffer[size+2];\n\tuint16_t sum = 0;\n\tbuffer[0] = PID;\n\tfor (int i=0; i&lt;size; i++)\n\t{\n\t\tbuffer[i+1] = data[i];\n\t}\n\n\tfor (int i=0; i&lt;size+1; i++)\n\t{\n\t\tsum += buffer[i];\n\t\tif (sum&gt;0xff) sum = sum-0xFF;\n\t}\n\n\tsum = 0xFF-sum;\n\treturn sum;\n}<\/pre><\/div>\n\n\n\n<p>The function is static since it is related to this source file and not another one.<\/p>\n\n\n\n<p>Also, the function to calculate the protected ID as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">static uint8_t pid_Calc (uint8_t ID)\n{\n\tuint8_t IDBuf[6];\n\tfor (int i=0; i&lt;6; i++)\n\t{\n\t\tIDBuf[i] = (ID&gt;&gt;i)&amp;0x01;\n\t}\n\tuint8_t P0 = (IDBuf[0]^IDBuf[1]^IDBuf[2]^IDBuf[4])&amp;0x01;\n\tuint8_t P1 = ~((IDBuf[1]^IDBuf[3]^IDBuf[4]^IDBuf[5])&amp;0x01);\n\tID = ID | (P0&lt;&lt;6) | (P1&lt;&lt;7);\n\treturn ID;\n}<\/pre><\/div>\n\n\n\n<p>Next a function that allow us to send single byte over LIN bus as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">static void LIN_SendByte(uint8_t data)\n{\n    while (!(USART1-&gt;SR &amp; USART_SR_TXE)); \/\/ Wait until TX is empty\n    USART1-&gt;DR = data;                    \/\/ Send data\n}<\/pre><\/div>\n\n\n\n<p>The function shall take uint8_t data argument and return nothing.<\/p>\n\n\n\n<p>The function is the same as sending data over uart using register level.<\/p>\n\n\n\n<p>Next, the main function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">uint8_t LIN_Transmit_Data(uint8_t ID, uint8_t *data, uint16_t len)\n{\n\tif (ID &gt; 0x3F) return -1;\n\n\tif(len&gt;8) return -1;\n\n\n\tuint8_t PID=pid_Calc(ID);\n\n\tuint8_t checkSum=checksum_Calc(PID,data,len);\n\n\n\tUSART1-&gt;CR1 |= USART_CR1_SBK;  \/\/ Send Break\n\n\tLIN_SendByte(0x55); \/\/sync field\n\tLIN_SendByte(PID); \/\/PID\n\tfor (int i=0;i&lt;len;i++)\n\t{\n\t\tLIN_SendByte(data[i]);\n\t}\n\tLIN_SendByte(checkSum);\n\n\treturn 0;\n\n}<\/pre><\/div>\n\n\n\n<p>In order to send data over LIN bus, we need first to arrange the data in certain way.<\/p>\n\n\n\n<p>First, check if the ID is bigger than 0x3F then it is not valid and return -1.<\/p>\n\n\n\n<p>Also, if the data length is more than 8 byte, return -1 since the maximum is 8 byte.<\/p>\n\n\n\n<p>Once the conditions are met, calculate the PID from the passed ID.<\/p>\n\n\n\n<p>Do checksum to the message to be sent by including also the data to be transmitted and the length of the data.<\/p>\n\n\n\n<p>Once the data has been structured correctly, we start the transmission by sending the Break signal as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"312\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-57-34-1024x312.jpg\" alt=\"\" class=\"wp-image-3280\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-57-34-1024x312.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-57-34-300x91.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-57-34-768x234.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-57-34-1536x468.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-57-34-2048x623.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-57-34-1150x350.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-57-34-750x228.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-57-34-400x122.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-57-34-250x76.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">USART1-&gt;CR1 |= USART_CR1_SBK;  \/\/ Send Break<\/pre><\/div>\n\n\n\n<p>Then transmit the sync field as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">LIN_SendByte(0x55); \/\/sync field<\/pre><\/div>\n\n\n\n<p>Then the PID:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">LIN_SendByte(PID); \/\/PID<\/pre><\/div>\n\n\n\n<p>Next transmit the data:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">for (int i=0;i&lt;len;i++)\n{\n  LIN_SendByte(data[i]);\n}<\/pre><\/div>\n\n\n\n<p>Finally, send the checksum as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">LIN_SendByte(checkSum);<\/pre><\/div>\n\n\n\n<p>Return 0 to indicate the success.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">return 0;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Thats all for developing the source file.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. Connecting the Logic Analyzer:<\/h2>\n\n\n\n<p>You can connect CH0 of the logic analyzer to the PA9 (D8 of Arduino Uno pins) as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"645\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-35-02-1024x645.jpg\" alt=\"\" class=\"wp-image-3281\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-35-02-1024x645.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-35-02-300x189.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-35-02-768x484.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-35-02-1536x968.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-35-02-2048x1291.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-35-02-1150x725.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-35-02-750x473.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-35-02-400x252.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/2025-03-08_11-35-02-250x158.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">7. Testing the Driver:<\/h2>\n\n\n\n<p>In main.c file.<\/p>\n\n\n\n<p>In user code begin includes, include LIN.h as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;LIN.h&quot;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>In user code begin PV, declare a buffer to hold the data to be transmitted as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">uint8_t LINData[8];<\/pre><\/div>\n\n\n\n<p>In user code begin 2 in main function, fill the buffer with data as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\tfor (int i=0; i&lt;8; i++)\n\t{\n\t\tLINData[i+2] = i;\n\t}<\/pre><\/div>\n\n\n\n<p>In user code begin 3 in while 1 loop, transmit the data with ID 0x34 as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t  LIN_Transmit_Data(0x34, LINData, 8);<\/pre><\/div>\n\n\n\n<p>Delay by amount of 100ms as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">HAL_Delay(100);<\/pre><\/div>\n\n\n\n<p>Save the project, build it and run it on your STM32F4 board.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/07\/2024-07-12_15-03-3.jpg\" alt=\"\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">8. Results:<\/h2>\n\n\n\n<p>Here, I am using oscilloscope to decode the data and you should get the following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"630\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/RigolDS2.png\" alt=\"\" class=\"wp-image-3282\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/RigolDS2.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/RigolDS2-300x185.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/RigolDS2-768x473.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/RigolDS2-750x461.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/RigolDS2-400x246.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/03\/RigolDS2-250x154.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Everything look great and we have successfully transmitted data over LIN bus.<\/p>\n\n\n\n<p>In part 3, we shall start receiving data over LIN bus<\/p>\n\n\n\n<p>Stay tuned and happy coding \ud83d\ude09<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In part 2 of LIN guide, we shall start transmitting data over LIN bus and decode them using either oscilloscope or logic analyzer. In this guide, we shall cover the following: 3. Creating Source and Header Files: After the project has been generated, right click on src folder and add new source file as following: [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,11,12],"tags":[],"class_list":["post-3276","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/3276"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3276"}],"version-history":[{"count":2,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/3276\/revisions"}],"predecessor-version":[{"id":3284,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/3276\/revisions\/3284"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}