Software UART TX sample (CY8CKIT-059)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hello Moto-san, 

 

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

 

Best regards, 
Hari

Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

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
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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