[En-Nut-Discussion] UART0 receive problem

Prasad.Nagapati at infineon.com Prasad.Nagapati at infineon.com
Thu Jun 11 08:12:18 CEST 2009


 
Hi Harald,

As you mentioned I am using UART1 now, and connected it to directly the
smart card I/O line which operates at +5V.
Smart card settings are 9600, 8 data bit, Even parity, 1 stop bit. Even
I configured the same in my code also.

But I am getting random data, what could be the reason, do I need an
inverter before connecting to the Rx of UART1?

Please help me regarding this. Sample code below

/*
 * Sniffer code sample.
 */
int main(void)
{
    int got;
    int i;
    u_long baud = 9600;
	unsigned char parity = 2; // even parity
	unsigned char stopBit = 1; // 1 stop bit
    FILE *uart;
	FILE *uart1;
    TCPSOCKET *sock;
    u_char mac[6] = { 0x00, 0x06, 0x98, 0x00, 0x00, 0x55 };

    /* UART0*/
	NutRegisterDevice(&DEV_UART, 0, 0);
    uart = fopen(DEV_UART_NAME, "r+");

    _ioctl(_fileno(uart), UART_SETSPEED, &baud);
	_ioctl(_fileno(uart), UART_SETPARITY , &parity);
	_ioctl(_fileno(uart), UART_SETSTOPBITS, &stopBit);

	/*UART1 */

	NutRegisterDevice(&DEV_UART1, 0, 0);
	uart1 = fopen(DEV_UART1_NAME, "r+");
    _ioctl(_fileno(uart1), UART_SETSPEED, &baud);
	_ioctl(_fileno(uart1), UART_SETPARITY , &parity);
	_ioctl(_fileno(uart1), UART_SETSTOPBITS, &stopBit);

	/* ETHERNUT */
	NutRegisterDevice(&DEV_ETHER, 0x8300, 5);
    NutNetLoadConfig(DEV_ETHER_NAME);
    memcpy(confnet.cdn_mac, mac, 6);
    NutNetSaveConfig();

    /*
     * Setup the ethernet device. Try DHCP first. If this is
     * the first time boot with empty EEPROM and no DHCP server
     * was found, use hardcoded values.
     */
    if (NutDhcpIfConfig("eth0", 0, 60000)) 
	{
        if (NutDhcpIfConfig("eth0", mac, 60000)) 
		{
            u_long ip_addr = inet_addr("192.168.192.100");
            u_long ip_mask = inet_addr("255.255.255.0");

            NutNetIfConfig("eth0", mac, ip_addr, ip_mask);
            /* If not in a local network, we must also call 
               NutIpRouteAdd() to configure the routing. */
        }
    }

	fprintf(uart,"IP: %s\n", inet_ntoa(confnet.cdn_ip_addr));


    /*
     * The low level function read() will grab all available bytes 
     * from the input buffer. If the buffer is empty, the call will
     * block until something is available for reading.
     */
    /*
        * Create a socket.
        */
    if ((sock = NutTcpCreateSocket()) != 0) 
	{
        /*
            * Listen on port 23. If we return, we got a client.
            */
        if (NutTcpAccept(sock, 23) == 0) 
		{

            /*
                * Open a stream and associate it with the socket, so 
                * we can use standard I/O. Note, that socket streams
                * currently do support text mode.
                */
            if ((stream = _fdopen((int) sock, "r+b")) != 0) 
			{
				/*
				* Send a welcome banner.
				*/
				fputs_P(banner_P, stream);
				/*
				* Flush output and read a line.
				*/
				fflush(stream);
				for (i = 0;; i++) 
				{
					int i;

					got = _read(_fileno(uart1),
inbuf, sizeof(inbuf));
					
					fprintf(stream,"bytes read
%d\r\n",got);
					for(i=0;i<got;i++)
					{
	
fprintf(stream,"\nrecieved char is %x",inbuf[i]);
					}
					fprintf(stream,"\r\n");
					
				}
				
			}
		}
	}
	/*
     * Nut/OS never expects a thread to return. So we enter an 
     * endless loop here.
     */
    /*
        * Close our socket.
        */
    NutTcpCloseSocket(sock);
	while(1);
}


Regards
Prasad


-----Original Message-----
From: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] On Behalf Of Harald Kipp
Sent: Wednesday, June 10, 2009 11:02 PM
To: Ethernut User Chat (English)
Subject: Re: [En-Nut-Discussion] UART0 receive problem

Prasad.Nagapati at infineon.com wrote:

> I need a help, basically I want to tap the I/O  line between a smart 
> card and smart card reader.
> 
> For this I am using JNUT board 1.3H, where I want to connect the UART0

> Rx line to the above mentioned I/O line.
> 
> What is the extra circuitry I need to Tap this I/O line.
> 
> Is it sufficient to connect the I/O line from smart card via a pull up

> resistor to the Rx pin of UART0? Or there is a level shifter is 
> required?
> 
> Smart card also works in the +5V,

If the smart card interface is 5V then you simply connect expansion port
pin 39. And, of course, GND (pins 5, 6, 7 or 8).

First problem:
You need to remove R18, otherwise the RX output of IC6 will work against
your smart card and one of them will become damaged sooner or later.
This is an intentionally larger SMD resistor, so it shouldn't be too
difficult to remove it.

Second problem:
Needless to say that, after removing R18, your receiver at the DB-9 is
gone.

Third problem:
When programming the board, you need to remove the new connection at pin
39. Otherwise programming will fail.

To avoid all these problems, why not use UART1 and connect the smart
card to expansion port pin 57?

Here's the expansion port layout
http://www.ethernut.de/en/hardware/enut1/ports.html
(Do not mount R33! This is for UART1 routed to the DB-9 only.)

For the software use

NutRegisterDevice(&DEV_UART1, 0, 0);
fp = fopen(DEV_UART1_NAME, "r+");
fread(fp,....);

The big advantage is, that you don't need to modify the hardware and
UART0 at the DB-9 connector is still available.

Harald

_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion



More information about the En-Nut-Discussion mailing list