cancel
Showing results for 
Search instead for 
Did you mean: 

Code Examples

MotooTanaka
Esteemed Contributor

Hi,

I have just posted this to a discussion below for a possible solution.

https://community.cypress.com/t5/PSoC-5-3-1-MCU/PSoC5LP-Why-can-t-I-fit-this-UART-into-my-available-...

But as this could be useful when you have used up all UART components and you need yet another UART TX,

I'm posting this here, too.

schematic

002-schematic.JPG

pins (or "a pin" ?)

003-pins.JPG

main.c

#include "project.h"
#include "stdio.h"

#define STR_BUF_LEN 64
#define BIT_DELAY_US 104 /* 9600Hz -> 104.17us */

void soft_tx_send_byte(uint8_t data)
{
    uint8_t mask = 0x01 ;
    int i ;
    
    soft_tx_Write(1) ; /* make sure that the level is high */
    CyDelayUs(BIT_DELAY_US * 2) ;
    soft_tx_Write(0) ; /* generate start bit */
    CyDelayUs(BIT_DELAY_US) ;
    for (i = 0; i < 8; i++ ) {
        if (mask & data) {
            soft_tx_Write(1) ;
        } else {
            soft_tx_Write(0) ;
        }
        mask <<= 1 ;
        CyDelayUs(BIT_DELAY_US) ;
    }
    soft_tx_Write(1) ; /* generate stop bit */
    CyDelayUs(BIT_DELAY_US * 2) ;
}

void soft_tx_send_string(char *str)
{
    while(str && *str) {
        soft_tx_send_byte(*str++) ;
    }
}

int main(void)
{
    char str[STR_BUF_LEN+1] ;
    int count = 0 ;
    
    CyGlobalIntEnable; /* Enable global interrupts. */
    
    soft_tx_send_string("\x1b[2J\x1b[;H") ;
    soft_tx_send_string("Test Software UART TX ") ;
    snprintf(str, STR_BUF_LEN, "(%s %s)\n\r", __DATE__, __TIME__) ;
    soft_tx_send_string(str) ;

    for(;;) {
        snprintf(str, STR_BUF_LEN, "count %d\n\r", count++) ;
        soft_tx_send_string(str) ;
        CyDelay(1000) ;
    }
}

Tera Term log

001-TeraTerm-log.JPG

moto

3 Replies
Hari
Moderator
Moderator

Hello Moto-san, 

 

Thank you for sharing this project with the community and for your interest in our products. 

 

Best regards, 
Hari

Len_CONSULTRON
Honored Contributor II

moto-san,

Thank you for posting your SW UART Tx project.

I'm a little confused.   Is there a SW Tx UART already in the components lib from Infineon?

Len_CONSULTRON_0-1618864202429.png

Len
"Engineering is an Art. The Art of Compromise."
MotooTanaka
Esteemed Contributor

Len-san,

Thank you for your pointing out this.

I also thought about that component, but as I was not sure if the component was available for this device, I wrote one manually.

Probably using available component must be a better/safer.

moto

0 Likes