Buffer on UART3

Platform for Telematic Applications
Post Reply
maze38
Posts: 9
Joined: Tue 29. Nov 2016, 08:45

Buffer on UART3

Post by maze38 » Fri 2. Dec 2016, 11:15

Hi,
I plug a RFID reader on the serial port (38400 baud). In my main loop I wrote a RFID_Task which read the UART3.

Code: Select all

void RFID_task()
{
	static u16_t ret=0;
	u8_t temp[8];
	
	ret = UART_read(temp,8,UART3);
		
	if(ret > 0)	
	{
		UART_write("OK\r\n",sizeof("OK\r\n"),UART3);
		UART_write(temp,8,UART3);
		  UART_write("\r\n",sizeof("\r\n"),UART3);
		
		led_setPattern (LED_ON, LED_2, LED_GREEN);
		Set_RFID(temp);
	}
}
before I change the serial port speed to 38400.

Code: Select all

void change_UART3()
{
	// Vitesse du port a 38400
	unsigned long tmp;
	VICIntEnClr |= (1<<29); //Disable interrupt UART3
	tmp = U3LCR;
	U3LCR = 0x80 | tmp; // DLAB=1 , enable writeaccess to divisor latch register
	U3DLL = 74;  //UDLL 
	U3DLM = 0;	//UDLM;
	U3FDR = (12<<4) | (7&0xF);   //(MulVal<<4) | (DivAddVal&0xF)
	U3LCR = tmp;  // DLAB=0 , disable writeaccess to divisor latch register
	VICIntEnable |= (1<<29); //Interrupt Enable UART3
}
My RFID_task function read only one bit !!!
is it possible to create a buffer on UART3 and read 8 bit ?

Thanks

Best Regards

S.Michaelsen
Hardware Development
Hardware Development
Posts: 73
Joined: Fri 10. Sep 2010, 13:11

Re: Buffer on UART3

Post by S.Michaelsen » Mon 5. Dec 2016, 09:52

Hi,

I assume you are talking about byte rather than bit, right?

The read function is non blocking. It returns only the number of bytes that are currently available and that fit into the read buffer. If you need exactly 8 byte before you can process the data you could for example simply read the bytes one by one until you read 8 bytes and process them afterwards.

Best Regards,
Stephan

maze38
Posts: 9
Joined: Tue 29. Nov 2016, 08:45

Re: Buffer on UART3

Post by maze38 » Tue 6. Dec 2016, 13:58

Thanks,

I try to use the same code as I find in sms.c example.

Code: Select all

	ret = UART_read(&buff,1,UART3);
		
	if(buff == '\n' && buffLen == 0)	ret = UART_read(&buff,1,UART3);
	while(ret)
	{
		buffer[buffLen] = buff;
		buffLen++;
		if(buffLen == 400)
			buffLen = 0;
		if(buff == '\r')
			break;
		ret = UART_read(&buff,1,UART3);
	}

	if((buffer[buffLen-1] == '\r') && (buffLen != 0))
	{
		u8_t * ActChar;
               ...
       }
I send 12345678\r\n but only one byte is read and not necessarily the first one !!
is there a error in this code ? or do I have to change something because of my transmission rate (38400 baud) ?

Best regards

Stephane

S.Michaelsen
Hardware Development
Hardware Development
Posts: 73
Joined: Fri 10. Sep 2010, 13:11

Re: Buffer on UART3

Post by S.Michaelsen » Thu 8. Dec 2016, 09:36

Hi,

so if you try to read ten bytes the loop condition might be the wring one. The while(ret){...} loop will stop the first time when there is nothing to read - at 38400 baud the processor might be much faster with processing the loop then it takes to transmit another byte. Again: the function UART_read(...) is non blocking! if there is nothing to read yet it returns 0. So you may need to modify the code to your needs!

Post Reply