Juan Esteban Paz
Published © CC BY

UART Interface PC PSOC

A very simple interface for debugging or operating an embedded system can be easily configured with UART. Works great for data acquisition.

IntermediateProtip27 minutes4,808
UART Interface PC PSOC

Things used in this project

Hardware components

PSoC 4 Pioneer Kit
Cypress PSoC 4 Pioneer Kit
×1

Software apps and online services

Putty
Open source SSH and telnet client

Story

Read more

Schematics

UART PSoC workspace

PSOC Workspace

Code

UART Interface demo Code

C/C++
Some work must be done to personalize the demo modes
/* ========================================
 * Copyright Juan Esteban Paz, 2014
 * All Rights Reserved
 * UNPUBLISHED, LICENSED SOFTWARE.
 * ========================================*/

#include <stdlib.h> 
#include <project.h>

//function prototypes
void Init();
CY_ISR(UARTRX);

//UART variables
#define CR 0x0D
#define LF 0x0A
#define NewLine() UART_UartPutChar(CR); UART_UartPutChar(LF);
char volatile ch; 
char msg[7];
int e;

void message(){//Standard message this works if the same data will be used over and over again
	NewLine();	
	UART_UartPutString("variable feedback");//power	
	/* To output numerical data use itoa to convert numbers to a char array or string
    itoa(x*10,msg,10);
	UART_UartPutString(msg);*/
}
void Uartdec(char ch){
 //UART DECODING					
    switch(ch){                            
    	case('1'):{	////Case ch =1///	
            NewLine();
            UART_UartPutString("Stopped");
            e=1;
    		break;}			   
    	case('2'):{//Case ch =2
    		NewLine();
    		UART_UartPutString("Mode A");					
    		e=2;
       		break;}
        case('3'):{//Case ch =3
            NewLine();
       		UART_UartPutString("Mode B");	
            e=3;
    		break;}
    	/*default:{//Case ch = different value than above
    		NewLine();
       		UART_UartPutString("Mode");					
    		e=0;
    	}*/
    }	
}

int main()
{       
    CyGlobalIntEnable;
    Init();	    
	for(;;){
        //Running Mode selection
		switch(e){		
			case(1):{
                //Mode 1
                break;
			}
            case(2):{	   
                //Mode 2
                //message(); //this will start sending data message through UART 
				break;
			}
            case(3):{	        
                 //Mode 3    
				break;
            }
            case(0):{                  
				//default Mode
				//NewLine();
                break;
            }
		}
       
	}    
}
void Init(){            
    UART_Start();
    NewLine();
	UART_UartPutString("UART interface");	
    NewLine();
	UARTISR_StartEx(UARTRX);
}
CY_ISR(UARTRX){
    UARTISR_Disable();
    ch=UART_UartGetChar(); 
    //UART_UartPutChar(ch); //This helps to verify the character that was read by the UART  
	if (0!=ch) Uartdec(ch);       
    UART_ClearRxInterruptSource(UART_INTR_RX_NOT_EMPTY);
    UARTISR_Enable();
}

Credits

Juan Esteban Paz
13 projects • 27 followers
Mechanical and Electrical Engineer enjoy working with PSOC

Comments