- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, everyone. I'm doing a project in the PSOC but I have a problem when the PSOC receives data that arduino sends and I want to send it to the LCD I can not see the data and when I use the statement UART_WriteTxData (xxx); so that what arrives from the arduino send it to the PC if I can see the data well.
When i use
UART_WriteTxData (xxx); I can see the data and when I use
UART_PutString (xxx);
I can not see them well
/* ========================================
*
* Copyright YOUR COMPANY, THE YEAR
* All Rights Reserved
* UNPUBLISHED, LICENSED SOFTWARE.
*
* CONFIDENTIAL AND PROPRIETARY INFORMATION
* WHICH IS THE PROPERTY OF your company.
*
* ========================================
*/
#include "project.h"
#include <stdlib.h>
#include <stdio.h>
int fila;
int columna;
int q;
/***Variables para ADC**/
int32 entero[2],voltaje[2];
float32 volt[2];
float aux[2];
char str[16];
char str3[16];
char str4;
/*******UART********/
int recibir=0;
/************************/
unsigned int rango;
unsigned int tx=0;
unsigned int limite=4;
/********UART*******/
char str2[16];
/*********************/
int bit0_MSB,bit1,bit2,bit3_LSB,cuenta=0,numeroint=0;
char i='\0';
char numero[5];
/*************Teclado matricial*******/
char8 Keypad_1_Key[4][4]={
{'1','4','7','*'},
{'2','5','8','0'},
{'3','6','9','#'},
{'A','B','C' ,'D'}
};
/**********valores teclado********/
void LeerTecla(){
bit0_MSB=Bit0_MSB_Read();
bit1=Bit1_Read();
bit2=Bit2_Read();
bit3_LSB=Bit3_LSB_Read();
if((bit0_MSB==0)&&(bit1==0)&&(bit2==0)&&(bit3_LSB==0))//1
i=Keypad_1_Key[0][0];
if((bit0_MSB==0)&&(bit1==0)&&(bit2==0)&&(bit3_LSB==1))//2
i=Keypad_1_Key[1][0];
if((bit0_MSB==0)&&(bit1==0)&&(bit2==1)&&(bit3_LSB==0))//3
i=Keypad_1_Key[2][0];
if((bit0_MSB==0)&&(bit1==0)&&(bit2==1)&&(bit3_LSB==1))//A
i=Keypad_1_Key[3][0];
if((bit0_MSB==0)&&(bit1==1)&&(bit2==0)&&(bit3_LSB==0))//4
i=Keypad_1_Key[0][1];
if((bit0_MSB==0)&&(bit1==1)&&(bit2==0)&&(bit3_LSB==1))//5
i=Keypad_1_Key[1][1];
if((bit0_MSB==0)&&(bit1==1)&&(bit2==1)&&(bit3_LSB==0))//6
i=Keypad_1_Key[2][1];
if((bit0_MSB==0)&&(bit1==1)&&(bit2==1)&&(bit3_LSB==1))//B
i=Keypad_1_Key[3][1];
if((bit0_MSB==1)&&(bit1==0)&&(bit2==0)&&(bit3_LSB==0))//7
i=Keypad_1_Key[0][2];
if((bit0_MSB==1)&&(bit1==0)&&(bit2==0)&&(bit3_LSB==1))//8
i=Keypad_1_Key[1][2];
if((bit0_MSB==1)&&(bit1==0)&&(bit2==1)&&(bit3_LSB==0))//9
i=Keypad_1_Key[2][2];
if((bit0_MSB==1)&&(bit1==0)&&(bit2==1)&&(bit3_LSB==1))//C
i=Keypad_1_Key[3][2];
if((bit0_MSB==1)&&(bit1==1)&&(bit2==0)&&(bit3_LSB==0))//*
i=Keypad_1_Key[0][3];
if((bit0_MSB==1)&&(bit1==1)&&(bit2==0)&&(bit3_LSB==1))//0
i=Keypad_1_Key[1][3];
if((bit0_MSB==1)&&(bit1==1)&&(bit2==1)&&(bit3_LSB==0))//#
i=Keypad_1_Key[2][3];
if((bit0_MSB==1)&&(bit1==1)&&(bit2==1)&&(bit3_LSB==1))//D
i=Keypad_1_Key[3][3];
}
/**********rutina leer teclado********/
CY_ISR(LeerTeclaInt){
LeerTecla();
if((i!='A')&&(i!='B')&&(i!='C')&&(i!='D')&&(i!='*')&&(i!='#'))
{
if(cuenta<=3)
{
numero[cuenta]=i;
cuenta++;
}
}
if(i=='B')
{
numero[0]='\0';
numero[1]='\0';
numero[2]='\0';
numero[3]='\0';
cuenta=0;
}
if(i=='A')
{
numeroint=atoi(numero);
}
if(i=='*')
{
DIR_Write(0);
STEP_Write(1);
CyDelay(10);
STEP_Write(0);
CyDelay(100);
}
if(i=='#')
{
DIR_Write(1);
STEP_Write(1);
CyDelay(10);
STEP_Write(0);
CyDelay(100);
}
}
/*********Envio interrupcion********/
CY_ISR(Enviar)
{
sprintf(str3,"%d %d %d \n \r",recibir,voltaje[0],voltaje[1]);
UART_PutString(str3);
}
////////////////////////////////////////////////////////////////////////////////HERE
/**************Rutina recibir datos UART********/
CY_ISR(InterrupRX)
{
while(UART_GetRxBufferSize()>=1)
{
recibir=UART_GetChar();
//UART_WriteTxData(recibir);
}
}
////////////////////////////////////////////////////////////////////////////////HERE
/*************************************************/
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
I2C_Start(); //Inicializar el I2C
LCD_I2C_start(); //Inicializar la lcd
Opamp_Start();//Inicializa Opam
Opamp2_Start();
pulisr_StartEx(LeerTeclaInt);//Interrupcion
isrEnvio_StartEx(Enviar);
isrRX_StartEx(InterrupRX);
/***********UART****/
UART_Start();
/***************ADC******************/
ADC_Start();
/****************MUX*******************/
AMux_1_Start();
/***************************************/
columna=0;
fila=0;
LCD_I2C_setCursor(columna,fila);
LCD_I2C_print("Ingresa los valores ");
columna=0;
fila=1;
LCD_I2C_setCursor(columna,fila);
LCD_I2C_print("en MiliNewton(mN)");
CyDelay(600);
LCD_I2C_clear();
for(;;)
{
/****************Galga*****/
columna=0;
fila=2;
LCD_I2C_setCursor(columna,fila);
LCD_I2C_print("mN=");
/***************************/
sprintf(str4,"%d",recibir);
columna=3;
fila=2;
LCD_I2C_setCursor(columna,fila);
LCD_I2C_print(str4);
LCD_I2C_print(" ");
/**********************Canal1************************/
AMux_1_FastSelect(0);
columna=0;
fila=3;
LCD_I2C_setCursor(columna,fila);
LCD_I2C_print("mV=");
/********ADC*********/
ADC_StartConvert();
ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
entero[0]=ADC_GetResult32();
ADC_StopConvert();
voltaje[0]=ADC_CountsTo_mVolts(entero[0]);
aux[0]=voltaje[0];
/*********************/
sprintf(str,"%.0f",aux[0]);
columna=3;
fila=3;
LCD_I2C_setCursor(columna,fila);
LCD_I2C_print(str);
LCD_I2C_print(" ");
/***********************************************/
/**********************Canal2*************************/
AMux_1_FastSelect(1);
columna=10;
fila=3;
LCD_I2C_setCursor(columna,fila);
LCD_I2C_print("mV=");
/********ADC*********/
ADC_StartConvert();
ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
entero[1]=ADC_GetResult32();
ADC_StopConvert();
voltaje[1]=ADC_CountsTo_mVolts(entero[1]);
aux[1]=voltaje[1];
/*********************/
sprintf(str2,"%.0f",aux[1]);
columna=13;
fila=3;
LCD_I2C_setCursor(columna,fila);
LCD_I2C_print(str2);
LCD_I2C_print(" ");
/***********************************************/
if((i!='A')&&(i!='C'))//SI no se presiona A ni C
{
columna=0;
fila=0;
LCD_I2C_setCursor(columna,fila);
LCD_I2C_print("Ingrese Valor");
columna=0;
fila=1;
LCD_I2C_setCursor(columna,fila);
LCD_I2C_print("mN=");
columna=3;
fila=1;
LCD_I2C_setCursor(columna,fila);
if(cuenta<5)
LCD_I2C_print(numero);
}
if(i=='A')//Si se presiona A
{
columna=0;
fila=0;
LCD_I2C_setCursor(columna,fila);
LCD_I2C_print("Estirando fibra");
do
{
AMux_1_FastSelect(0);
columna=0;
fila=2;
LCD_I2C_setCursor(columna,fila);
LCD_I2C_print("mN=");
/********ADC*********/
ADC_StartConvert();
ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
entero[0]=ADC_GetResult32();
ADC_StopConvert();
voltaje[0]=ADC_CountsTo_mVolts(entero[0]);
aux[0]=voltaje[0];
/*********************/
sprintf(str,"%.0f",aux[0]);
columna=3;
fila=2;
LCD_I2C_setCursor(columna,fila);
LCD_I2C_print(str);
LCD_I2C_print(" ");
/*********************/
if(voltaje[0]<numeroint)
{
DIR_Write(0);
STEP_Write(1);
CyDelay(10);
STEP_Write(0);
CyDelay(100);
}
if(voltaje[0]>numeroint)
{
DIR_Write(1);
STEP_Write(1);
CyDelay(10);
STEP_Write(0);
CyDelay(100);
}
rango=numeroint-voltaje[0];
}
while(rango>limite);
i='\0';
LCD_I2C_clear();
}
if(i=='B')//Si se presiona B
{
i='\0';
LCD_I2C_clear();
}
if(i=='C')//Si se presiona C
{
if(tx==0)
{
tx=1;
LCD_I2C_setCursor(0,0);
LCD_I2C_print(" Transmitiendo ");
i='\0';
/**********************/
PWM_Start();/*PWM*/
CyDelay(1000);
/***********************/
i='\0';
LCD_I2C_clear();
}
else
{
PWM_Stop();
tx=0;
i='\0';
LCD_I2C_clear();
}
}
}
}
/* [] END OF FILE */
I hope you can help me
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Would you mark my response as correct answer or helpful, it works for you?
Meantime, about your additional question.
Although I have not totally read your code yet,
assuming receive is a char or int,
I wonder if the value you are receiving is 0 ~ 9 or '0' ~ `9'?
If you are receiving 0 ~ 9
sprintf(str4, "%d", receive) makes sense
but if you are receiving '0' ~ '9' use
sprint(str4, "%c", receive)
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
To monitor each char being received,
how about using
UART_UartPutChar()
==========
CY_ISR(InterrupRX)
{
while(UART_GetRxBufferSize()>=1)
{
recibir=UART_GetChar();
//UART_WriteTxData(recibir);
UART_UartPutChar(recibir) ; // <----
}
}
==========
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh thanks if it served me but for example how could that variable be passed so that it is read correctly by an LCD because when I send it to it, it puts pure nonsense things and when I use this sprintf (str4, "% d", receive); what it does is that it does not complete the number or put another number that is not
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Would you mark my response as correct answer or helpful, it works for you?
Meantime, about your additional question.
Although I have not totally read your code yet,
assuming receive is a char or int,
I wonder if the value you are receiving is 0 ~ 9 or '0' ~ `9'?
If you are receiving 0 ~ 9
sprintf(str4, "%d", receive) makes sense
but if you are receiving '0' ~ '9' use
sprint(str4, "%c", receive)
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm not sure but when I sent it from arduino I sent it like this:
Serial.print (grams);
where grams is like:
int grams;
grams = fabs (i);
int i = LoadCell.getData ();
and well when I get to PSOC I pick it up like this:
int receive = 0;
char str4 [8];
CY_ISR (InterrupRX)
{
while (UART_GetRxBufferSize ()> = 1)
{
receive = UART_GetChar (); / * receive is of type int * /
// UART_WriteTxData (receive);
UART_PutChar (receive);
}
}
And then I want to send it to print to the LCD (I use the I2C protocol) like that;
sprintf (str4, "% d", receive);
LCD_I2C_print (str4);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would modify you function like
// assuming the value sent was "printable string"
#define STRBUF_LEN 8
int receive = 0 ;
int str_index = 0 ;
char str4[STRBUF_LEN+1] = {0} ; /* 1 more for NULL terminal char */
// str4[STRBUF_LEN] = 0 ;
CY_ISR(interruptRX)
{
while(UART_GetRxBufferSize() >= 1) {
receive = UART_GetChar() ;
UART_PutChar(receive) ; /* if this is written OK, that means the receive is '0'~'9' */
if (str_index < STRBUF_LEN) {
str4[str_index++] = receive ;
}
}
}
LCD_I2C_print(str4) ;
str_index = 0 ;
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Most likely you will hit a problem of printing with "%f" format next.
For that please refer to the following thread
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So it's fine I do not use floats thank you very much and I also realized that my program had an error because it was not printing the data, now noce if I can make a small donation with the help you have given me, another small thing when that thing shows more numbers beyond 999 you put them like this "001" or "014" leaves the first blank space should put the number 1 but it does not. Sorry for the delay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do you mean if you can do something like below?
==========
float f_data
...
sprintf(str, "%d.%03d", (int)f_data, ((int)(1000 * f_data + 0.5))%1000) ;
UART_UartPutString(str)
==========
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you can just show this
0000.0000.0000.0000.0000.0000.0000.0000.0000.0000.0000.0000.0000.0000.0000.00.00.00.0000.0000.0000.0000.0000.00
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
lol !
Well, can the program below (and attached) help you to understand what I meant?
============================
#include "project.h"
#include <stdio.h>
char str[128] ; /* print buffer */
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
}
int main(void)
{
float f_value ;
init_hardware() ;
sprintf(str, "Printing Float without %%f test (%s %s)\n", __DATE__, __TIME__) ;
UART_UartPutString(str) ;
while(1)
{
for (f_value = 0.000 ; f_value < 10.0 ; f_value += 0.321 ) {
sprintf(str, "As int: %d as \%%.1f: %d.%01d as \%%.2f: %d.%02d as \%%.3f: %d.%03d as \%%.4f: %d.%04d\n",
(int)(f_value + 0.5), /* I'm rounding here */
(int)(f_value + 0.05), ((int)(f_value * 10 + 0.5))%10, /* for 1 digit */
(int)(f_value + 0.005), ((int)(f_value * 100 + 0.5))%100, /* for 2 digits */
(int)(f_value + 0.0005), ((int)(f_value * 1000 + 0.5))%1000, /* for 3 digits */
(int)(f_value + 0.00005), ((int)(f_value * 10000 + 0.5))%10000 /* for 4 digits */
) ;
UART_UartPutString(str) ;
CyDelay(1000) ;
}
}
}
/* [] END OF FILE */
============================
With my CY8CKIT-044, the result log looks like
moto
P.S. BTW, I found a bug in my strategy and fixed it
for example for "%.1f" I was doing
sprintf(str, "%d.%01d", f_value, ((int)(f_value * 10 + 0.5))% 10) ;
but in case the value was 0.963, this came up as "0.0"
So I modified the format as
sprintf(str, "%d.%01d", (int)(f_value + 0.05), ((int)(f_value * 10 + 0.5))%10) ;
I learned, thank you!