{"id":18762216,"url":"https://github.com/liyanboy74/soft-uart","last_synced_at":"2025-04-06T00:06:57.470Z","repository":{"id":40677823,"uuid":"302661994","full_name":"liyanboy74/soft-uart","owner":"liyanboy74","description":"Multi Software Serial (UART) for STM32","archived":false,"fork":false,"pushed_at":"2025-02-13T05:44:34.000Z","size":13084,"stargazers_count":101,"open_issues_count":0,"forks_count":40,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T23:07:32.013Z","etag":null,"topics":["cubemx","hal","multi-software-serial","serial","soft-uart","softuart","software-serial","software-uart","stm32","uart","usart"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/liyanboy74.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-09T14:16:50.000Z","updated_at":"2025-03-26T09:46:54.000Z","dependencies_parsed_at":"2022-08-25T07:50:28.322Z","dependency_job_id":"60d87ab6-4bf8-4f25-ab19-b1d2b72f8aa5","html_url":"https://github.com/liyanboy74/soft-uart","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyanboy74%2Fsoft-uart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyanboy74%2Fsoft-uart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyanboy74%2Fsoft-uart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyanboy74%2Fsoft-uart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liyanboy74","download_url":"https://codeload.github.com/liyanboy74/soft-uart/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247415967,"owners_count":20935388,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cubemx","hal","multi-software-serial","serial","soft-uart","softuart","software-serial","software-uart","stm32","uart","usart"],"created_at":"2024-11-07T18:20:04.047Z","updated_at":"2025-04-06T00:06:57.442Z","avatar_url":"https://github.com/liyanboy74.png","language":"C","readme":"# Multi Software Serial (UART) For STM32\n\nThe library work fine for virtualize 6 UART full duplex in baud rate 9600.\nAll UART work together parallelly!\n\n\n\n### Library Dir:\n\n* [Softuart.h](./softuart.h)\n* [Softuart.c](./softuart.c)\n\n\n### Handler \u0026 baud rate\n\nThe function `SoftUartHandler(void)` must call in interrupt every `0.2*(1/BR)` .\n\nif `BR=9600` then `0.2*(1/9600)=20.8333333 uS` \n\n*highly recommended set maximum CPU clock for Run Handler faster as possible!*\n*you also available for use [lite](https://github.com/liyanboy74/soft-uart-lite) version by limited options for slow MCUs.*\n\nThe library doesn't change any GPIO config!\nbefore using must config TX pins as output and RX pins as input , any TX pin must set to HIGH and any RX pin must be Pullup.\n\n\n\n### Example Timer Config \n\n*for Baud Rate 9600 :*\n\n| Config                                                | value  |\n| :---------------------------------------------------- | :----- |\n| Timer Clock                                           | 72 MHz |\n| Prescaler (PSC - 16 bits value)                       | 74     |\n| Counter Period (AutoReload Register - 16 bits value ) | 19     |\n| auto-reload preload                                   | Enable |\n| Tim global interrupt                                  | Enable |\n\n*You also can use [Timer frequency calculator](https://github.com/liyanboy74/timer-frequency-calculator).*\n\n### Calling handler\n\n```c\nvoid HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)\n{\n\tif(htim-\u003eInstance==TIMX)\n\t{\n\t\tSoftUartHandler();\n\t}\n}\n```\n\n\n\n### Config Soft UART\n\nOpen `softuart.h` and edit bellow line as you want:\n\n```c\n#define \tNumber_Of_SoftUarts\t 6\n#define\t\tSoftUartTxBufferSize\t32\n#define\t\tSoftUartRxBufferSize\t64\n```\n\nIf `Number_Of_SoftUarts=6` that mean you `SoftUartNumber` is `0,1,2,3,4,5` \n\nAfter config timer for config Soft UART use `SoftUartInit`:\n\n```c\nSoftUartState_E SoftUartInit(uint8_t SoftUartNumber,GPIO_TypeDef *TxPort,uint16_t TxPin,GPIO_TypeDef *RxPort,uint16_t RxPin);\n```\n\n\n\n### Using Soft UART\n\nTransmit always is Possible but for Receiving data you must enable listening by calling:\n\n```c\nSoftUartState_E SoftUartEnableRx(uint8_t SoftUartNumber);\n```\n\nReceived data stored in buffer accessible by below functions:\n\n```c\nuint8_t \tSoftUartRxAlavailable(uint8_t SoftUartNumber);\nSoftUartState_E SoftUartReadRxBuffer(uint8_t SoftUartNumber,uint8_t *Buffer,uint8_t Len);\n```\n\nTransmit data:\n\n```c\nSoftUartState_E SoftUartPuts(uint8_t SoftUartNumber,uint8_t *Str,uint8_t Len);\nvoid \t\tSoftUartWaitUntilTxComplate(uint8_t SoftUartNumber);\n```\n\n\n### Example test:\n#### Transmit\n```c\nwhile(1)\n{\n\tSoftUartPuts(0,(uint8_t *)\"Hello\",5);\n\tSoftUartPuts(1,(uint8_t *)\"My\",2);\n\tSoftUartPuts(2,(uint8_t *)\"Name\",4);\n\tSoftUartPuts(3,(uint8_t *)\"Is\",2);\n\tSoftUartPuts(4,(uint8_t *)\"Esmaeill\",8);\n\tSoftUartPuts(5,(uint8_t *)\"--------\",8);\n}\n```\n![LogicAnalizer](https://user-images.githubusercontent.com/64005694/121798942-836e1380-cc3e-11eb-96bd-faa72cd72c03.jpg)\n\n#### Receive\n**Example 1:**\n\n```c\nuint8_t getchar(uint8_t SoftUartNumber)\n{\n    uint8_t ch;\n    while(SoftUartRxAlavailable(SoftUartNumber)==0);\n    SoftUartReadRxBuffer(SoftUartNumber,\u0026ch,1);\n    return ch;\n}\n```\n**Example 2:**\n\n```c\nuint8_t Buffer[SIZE],Len;\n\nwhile(1)\n{\n\t// Read \u003e= 10 Byte Data if Received\n\tif(Len=SoftUartRxAlavailable(0),Len\u003e=10)\n\t{\n\t\t// Move Received Data To Another Buffer\n\t\tif(SoftUartReadRxBuffer(0,Buffer,Len)==SoftUart_OK)\n\t\t{\n\t\t\t// Done\n\t\t}\n\t}\n}\n```\n\n**Full Example 3:**\n\n```c\n#include \"softuart.h\"\n\n...\n\nvoid HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)\n{\n\tif(htim-\u003eInstance == TIMX)\n\t{\n\t\tSoftUartHandler();\n\t}\n}\n\nuint8_t getchar(uint8_t SoftUartNumber)\n{\n    uint8_t ch;\n    while(SoftUartRxAlavailable(SoftUartNumber)==0);\n    SoftUartReadRxBuffer(SoftUartNumber,\u0026ch,1);\n    return ch;\n}\n\nint main(void)\n{\n    uint8_t ch;\n    \n    ...\n    \n    HAL_TIM_Base_Start_IT(\u0026htimX);\n    \n    SoftUartInit(0,SU_TX_GPIO_Port,SU_TX_Pin,SU_RX_GPIO_Port,SU_RX_Pin);\n    SoftUartEnableRx(0);\n    \n    ...\n    \n    while (1)\n    {\n        ch=getchar(0);\n        SoftUartPuts(0,\u0026ch,1);\n        //SoftUartWaitUntilTxComplate(0);\n        HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin);\n    }\n}\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliyanboy74%2Fsoft-uart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliyanboy74%2Fsoft-uart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliyanboy74%2Fsoft-uart/lists"}