- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Guys,
How can I see that UART is sending and receiving my command in PSoC designer ?
and what's the meaning of :
PRT0DR |= 0X80;
while(PRT0DR & 0X80)
any helps will be appreciated,
thank you
- Labels:
-
PSoC 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried to send character :
BYTE sel_card[4]={0xAB,0x02,0x01};
for (i=0;i<3;i++)
{
UART_1_PutChar(sel_card); // Send a character to UART TX port
}
and see in putty....it's sending something
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
is it because of baud rate ?
How can I get 9600 baud rate ?
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
You will need to send characters in ascii format to see it on the terminal.
For example,
UART_1_PutChar('A');
or UART_1_PutChar(0x41); // Hex
or UART_1_PutChar(65); // Dec
all will display single character A on your terminal.
Pls refer to the ASCII table
Make sure to convert your array elements to ascii using this table before displaying.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When you place the UART, there is a clock source selection, select the one the you want to use as the clock source, it can be one of the VC1, VC@ and VC3, or from other row input or outputs. the clock should be 8 times the baud rate, and you need to start the UART specifying the parity as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
PRT0DR |= 0X80;
while(PRT0DR & 0X80)
What is the intention of this code?
PRT0DR is the Port0 data register.
If your Port 0, Pin 7 is configured as output, above code will cause an infinite loop.
Most probably, I think it's set to Pull up drivemode, and the first statement enables the pullup.
The seconds line waits till it detects pin7 has been pulled down by an external switch/input.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
is it right for 9600 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I want to send :
AB 02 01 ? how can I do that ?
Please correct me if I'm wrong :
BYTE sel_card[3]={0xAB,0x02,0x01};
UART_1_CmdReset(); // Reset Command Buffer
UART_1_Start(UART_1_PARITY_NONE); // Start UART
UART_1_CmdReset();
for (i=0;i<3;i++)
{
UART_1_PutChar(sel_card); // Send a character to UART TX port
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9600 baud =
24 Mhz / 8 / 3 /20 =75000 hz
baud = 75000 Hz / 8 nearly 9600, is my calculation right ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The datasheet is not quite clear at this point, but I think you have to check the UART_bReadTxStatus() to see if the transmit-buffer is empty and may receive another character for transmission.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to create this logic :
Please correct me if I'm wrong :
BYTE sel_card[1]={0x01}; // Select Mifare card command return 10 bytes
for (i=0;i<1;i++)
{
UART_1_PutChar(sel_card); // Send a character to UART TX port
}
if(UART_1_cGetChar()==0x01)
{
byte_length = UART_1_cGetChar();
for (i=0;i<byte_length;i++)
{
RxdataBuff = UART_1_cGetChar(); // Get a character from UART RX data register
}
LCD_1_Position(0,0);
switch(RxdataBuff[1]) // Check status byte
{
case 0x02: // If 0x00 : Operation success
LCD_1_PrString(Cardf_Str); // Print "Card selected" on the LCD ;
LCD_1_Position(1,0);
LCD_1_PrCString("SN: ");
for (i=2;i<6;i++)
{
LCD_1_PrHexByte(RxdataBuff); // Print serial number of the card detected
}
break;
case 0x01:
LCD_1_PrString(Notag_Str); // Print "No tag" on the LCD ;
LCD_clr_line(1);
break;
case 0x0A:
LCD_1_PrString(Colli_Str); // Print "Collision occur" on the LCD ;
LCD_clr_line(1);
break;
case 0xF0:
LCD_1_PrString(Chksm_Str); // Print "Checksum error" on the LCD ;
LCD_clr_line(1);
break;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re clock:
You divider is around 2.4% off. your divider is 8 * 2 *20 = 320, I would try divider ot 312.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What's the different between :
UART_1_cReadChar() =='a'
UART_1_cGetChar()=='a'
I can see it sends character already with
UART_1_PutChar('a');
but when I used putty and send it to the board,
it didn't response to :
if (UART_1_cReadChar() =='a')
{
.....................
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
why is this "if" doesn't work ?
if(UART_1_cGetChar()=='a')
{
byte_length = UART_1_cGetChar();
for (i=0;i<byte_length;i++)
{
RxdataBuff = UART_1_cGetChar(); // Get a character from UART RX data register
}
LCD_1_Position(0,0);
switch(RxdataBuff[1]) // Check status byte
{
case 'a':
LCD_1_PrString(Cardf_Str); // Print "Card selected" on the LCD ;
LCD_1_Position(1,0);
LCD_1_PrCString("SN: ");
for (i=2;i<6;i++)
{
LCD_1_PrHexByte(RxdataBuff); // Print serial number of the card detected
}
break;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
to HL, how can you make it 312 ???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you use VC, it would be 8 * 3 * 13 or 8 * 39.
For testing purpose, using VC is Ok, I normally use timer/counter as divider.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
char UART_cGetChar(void)
Return character from RX Data register when valid data is available. Function does not return until character is received.
char UART_cReadChar(void)
Read RX Data register immediately. If valid data is not available, return 0, else ASCII char between 1 and 255 is returned.
You can find these information inside the datasheet of the UART UM.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
to HL
why is this "if" doesn't work ?
if(UART_1_cGetChar()=='a')
is it because of the speed ?
Thank you mate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi HL,
Any examples for : " I normally use timer/counter as divider."
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I sent 'a' to RX buffer but no response:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi bianchi,
can you provide us with an actual archive* of your project or even a subset of it that shows the non-working part. Maybe some of your settings in the chip-view are not as required. This will help us to answer several questions at once: How to set up a baud-rate-generator, and getting UART to work.
You did not tell (or I overlooked it) about the hardware you use, is it a PSoC1 developement kit or your own hardware. Do you use RS232-level shifters to meet the desired voltages on youe PC-side?
Bob
*) to do so: under "File -> Archive Project (complete)" there will be a .Zip archive generated which you may upload here as an attached file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
An earlier poster was incorrect on this -
PRT0DR |= 0X80;
while(PRT0DR & 0X80)
PRT0DR is the data register for Port 0. The register that controls drive mode is the
following -
Note PRT0DR |= 0X80; is a read/modify write intruction, and needs to be used
with a shadow register. See following discussion on shadow registers -
http://www.cypress.com/?rID=2900
http://www.cypress.com/?rID=39497
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In terms of coding style, if you are pressed for code space and speed,
switch statement may not be best approach, see -
http://www.cypress.com/?rID=45644
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have CPU_Clock set to SysClk/8, while you are debugging
you might consider SysClk/1. A key reason to set it at a slower
speed, therefore reduced MIPs, is for lower power, but if you have
a lot of code to execute keep the MIPs up until you can establish
you can satisfy all code MIP needs with reduced speed/power.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To Dana,
"switch statement may not be best approach, see" -
So better use "if" or you have a better solution ?
strange that, I only do a simple experiment but so hard to implement in cypress.....
a lot easier with AT89S52..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have CPU_Clock set to SysClk/8, while you are debugging
you might consider SysClk/1. A key reason to set it at a slower
speed, therefore reduced MIPs, is for lower power, but if you have
a lot of code to execute keep the MIPs up until you can establish
you can satisfy all code MIP needs with reduced speed/power.
Regards, Dana.
Reply : will it make my UART code working ? or still the same thing ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With CPU set to SysClk/8, or 3 Mhz, and VC1+ VC2 + VC3 set
to /8/3/13 your baudrate is 9600.
So I would think running CPU at 3 Mhz should be OK.
My comments on CASE statement were made w/o looking at your project.
Use of CASE is fine in your example project, its when your processor is
heavily loaded one might re-examine use of CASE.
When you display characters on LCD they have to be "displayable" characters.
In the case of the Hitachi there are a number of non displayable byte values,
as you can see in this chart. Same is true for a PC acting as a terminal.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The clock accuracy for a UART, see following -
http://www.cypress.com/?rID=39848
Regarding BYTE transmission by UART, there is no limitation on what
BYTE value you can send, its up to the Rx end to determine if it is a displayable
ASCII character or a command. As in prior post not all BYTE values can be dis-
played by LCD, but you could convert non displayable characters into a message
with suitable code.
Regards, Dana,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Dana for the response,
I'll try to re-code again with the simplest thing I want, without any case or something like that,
just send character and detect if there's character from PC ( putty )
It should work otherwise, I can say it's not easy to use cypress processor.....
It's only simple matter and the processor gives me too much trouble to implement...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I re-code them very simple only send 'a' and receive 'a'.....
Hopefully there's response, I'm testing it now
#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
#include <stdlib.h>
/*---------------------------------------------------------------------------------
void LCD_clr_line(unsigned char j)
function : clear LCD on line number j (0 or 1)
input line number j
----------------------------------------------------------------------------------*/
void LCD_clr_line(unsigned char j)
{
LCD_1_Position(j,0);
LCD_1_PrCString(" ");
}
void main(void)
{
BYTE i;
LCD_1_Start(); // Initialize LCD
UART_1_CmdReset(); // Reset Command Buffer
UART_1_Start(UART_1_PARITY_NONE); // Start UART
LCD_1_Position(0,0); // Set LCD position
LCD_1_PrCString("BaudRate = 9600 ");
LCD_1_Position(1,0); // Set LCD position
LCD_1_PrCString("Enter char a ");
while(1)
{
UART_1_CmdReset(); // Reset UART Command Buffer
for (i=0;i<1;i++)
{
UART_1_PutChar('a'); // Send a character ('a') to UART TX port
}
UART_1_CmdReset(); // Reset UART Command Buffer
if (UART_1_cGetChar() =='a')
{
LCD_1_Position(0,0);
LCD_1_PrCString("a char received");
}
else
{
LCD_1_Position(0,0);
LCD_1_PrCString("Cardreader error");
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried both :
char UART_cGetChar(void) | Return character from RX Data register when valid data is available. Function does not return until character is received |
int UART_ iReadChar(void) | Read Rx Data register immediately. If data is not available or an error condition exists, return an error status in the MSB. The received char is returned in the LSB. |
and both are not working ? is there anything missing here ??? so complicated for accepting only one simple 'a' charactrer ??
what's the different with :
BYTE UART_bReadRxData(void) | Return data in RX Data register without checking status of character is valid. |
only low level and high level API ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
if I use :
if (UART_1_cReadChar() =='a')
I got "Card reader error" and character 'a' is being sent into my laptop without stopping...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
how about :
if (UART_1_bReadRxData() == 0x61)
?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thats good news 'a' is showing up on laptop, in fact you are
in a continous while loop sending 'a's, so thats working.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thats good news 'a' is showing up on laptop, in fact you are
in a continous while loop sending 'a's, so thats working.
Regards, Dana.
to Dana
Yup it's working for sending character, but go back to my question, it can't receive 'a' character ?
is there any settings / code that I missed ?
It's very simple task and question, so please answer it with something simple too..
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The chip never does this task :
if (UART_1_cGetChar() == 'a')
{
LCD_clr_line(0);
LCD_clr_line(1);
LCD_1_Position(0,0);
LCD_1_PrCString("a char received");
}
I have no idea why....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I pushed 'a' character from my keyboard.....and there's no response....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried to test :
c = UART_1_cGetChar();
UART_1_PutChar(c);
nothing happened when I press any buttons on my computer ?
I don't understand in this poin, it's already very straight forward.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I cannot install desinger 5.3 at home so cannot check your project now.
Do you use the psoc evac kit /board to develope you project or you use your own board?
! would also check the following:
1. connect the tx output of posc to rx input of psoc ,
while
{
send 1 byte
read 1 char (use cgetChar)
print the received char.
wait 1 second
}
See if this works or not.
If it doesn't check then check and change your clock sync selection of UART.
Do not use cReadChar or iReadChar for now as it would return immedialy even nothing is received.