• AVR Freaks

AnsweredHot!Ring Buffer UART Using Harmony

Author
m_snaeem@hotmail.com
Starting Member
  • Total Posts : 37
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
2020/08/03 14:42:03 (permalink)
0

Ring Buffer UART Using Harmony

Hello,
i want to read 30 bytes in one ago using Ring Buffer. Once if i sent the data from putty I get correct data in the receiver register but when I try to send another 30 bytes the data is shifted -1 position which means 1st byte is shifted to 30th position and 2byte to the 1-byte position.
But I wanted to read every time new 30 bytes second time and so on. Is this is possible with a ring buffer or I have to use something else?
is it possible to flush out all the 30 bytes after reading these bytes so next time I get fresh 30-bytes. I am Using PIC32MX795F512L in harmony.
#1
nigelwright7557
Super Member
  • Total Posts : 471
  • Reward points : 0
  • Joined: 2006/11/06 08:15:51
  • Location: 0
  • Status: offline
Re: Ring Buffer UART Using Harmony 2020/08/03 14:44:58 (permalink)
0
Just use simple buffer then reset pointer at start of data.
#2
m_snaeem@hotmail.com
Starting Member
  • Total Posts : 37
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: Ring Buffer UART Using Harmony 2020/08/03 14:53:32 (permalink)
0
Actually i have to use Uart interrupt so when data received in uart receive register Receive callback register call without requesting any bytes.
Asit is not being occured in uart nonblocking mode. so i am using ring buffer. when i received 30 bytes callback register called it self
#3
ric
Super Member
  • Total Posts : 28386
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Ring Buffer UART Using Harmony 2020/08/03 15:36:29 (permalink)
0
Sounds like a bug in your code or your testing method.
A correctly implemented ring buffer won't lose any data. Are you sure you're not sending an extra byte (e.g. CR or LF) that you're not handling correctly?
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#4
m_snaeem@hotmail.com
Starting Member
  • Total Posts : 37
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: Ring Buffer UART Using Harmony 2020/08/04 00:48:40 (permalink)
0
I am sending exactly 30 bytes and debugger enters in the in Callback register and then check the register which has all of the byte which i sent but the problem is when i send again 34 bytes which has no CR or LP i get shifted results
#5
m_snaeem@hotmail.com
Starting Member
  • Total Posts : 37
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: Ring Buffer UART Using Harmony 2020/08/04 01:27:56 (permalink)
0
Also after sendling the data 3 or 4 time there is general exception bus error.
Can you suggest me what could be the solution??
 
#6
ric
Super Member
  • Total Posts : 28386
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Ring Buffer UART Using Harmony 2020/08/04 01:41:38 (permalink)
5 (1)
a bug somewhere in the code that you still have not shown.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#7
m_snaeem@hotmail.com
Starting Member
  • Total Posts : 37
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: Ring Buffer UART Using Harmony 2020/08/04 01:47:40 (permalink)
0
void QueueReceiver() {
UART4_Read(&ReceiveBuffer[0], sizeof (ReceiveBuffer));
Command = decryptMessage();
FifoIn(Command);
}
 
int main()
{
UART4_ReadCallbackRegister(QueueReceiver, (uintptr_t) NULL); 
UART4_ReadThresholdSet(34);
}
 
This is my code and i am send 34 bytes from putty to receive in UART e.g. $111201000000000004400431004300010
 
#8
ric
Super Member
  • Total Posts : 28386
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Ring Buffer UART Using Harmony 2020/08/04 01:49:33 (permalink)
0
Where is the definition of ReceiveBuffer?
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#9
m_snaeem@hotmail.com
Starting Member
  • Total Posts : 37
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: Ring Buffer UART Using Harmony 2020/08/04 01:51:24 (permalink)
0
uint8_t ReceiveBuffer[34];
i have attached settings also........!
post edited by m_snaeem@hotmail.com - 2020/08/04 01:58:01

Attached Image(s)

#10
m_snaeem@hotmail.com
Starting Member
  • Total Posts : 37
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: Ring Buffer UART Using Harmony 2020/08/04 01:53:07 (permalink)
2 (1)
I could not find any API to Flush the data in receive buffer or how to reset the pointer to save the bytes
#11
vgandhi
Senior Member
  • Total Posts : 44
  • Reward points : 0
  • Joined: 2016/10/24 21:28:35
  • Location: 0
  • Status: offline
Re: Ring Buffer UART Using Harmony 2020/08/04 03:00:41 (permalink) ☼ Best Answerby m_snaeem@hotmail.com 2020/08/04 03:26:53
5 (1)
To receive n characters, the RX buffer must be of size n+1. So, to receive 34 characters, set the receive buffer size to 35 in MHC. Also, you will need to enable the notifications by calling the below API.
UART4_ReadNotificationEnable(true, false);

There is no flush API available. But the Receive ring buffer can be flushed by calling -
UART4_Read((uint8_t*)rxBuffer, UART1_ReadCountGet());
   
#12
m_snaeem@hotmail.com
Starting Member
  • Total Posts : 37
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: Ring Buffer UART Using Harmony 2020/08/04 03:15:39 (permalink)
0
ric and vgandhi thanks for your help it is not being shifted now and remain same what I sent but if I try to send data after 1 second constantly then there is an exception error. after 5 to 6 times data sent.
could this happens due to ring buffer? 
#13
m_snaeem@hotmail.com
Starting Member
  • Total Posts : 37
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: Ring Buffer UART Using Harmony 2020/08/04 03:26:43 (permalink)
4 (1)
Thanks vgandhi
the error was due to buffer overflow.
Thanks for your help........!
 
#14
Antipodean
Super Member
  • Total Posts : 1908
  • Reward points : 0
  • Joined: 2008/12/09 10:19:08
  • Location: Didcot, United Kingdom
  • Status: offline
Re: Ring Buffer UART Using Harmony 2020/08/04 15:03:35 (permalink)
5 (1)
m_snaeem@hotmail.com
I could not find any API to Flush the data in receive buffer or how to reset the pointer to save the bytes



You don't need to flush a ring buffer and reset the pointers. It is called a ring buffer for a reason, go look on the web for an explanation of how it works.
 
secondly it pays to make the size of a ring buffer a power of 2, so in your case i would have it as 64 bytes. It is a lot easier to operate if it is larger than the message you expect instead of the exact message size.
 
Thirdly google for 'interrupt safe ring buffer'. This has the advantage that you don't need to worry about disabling interrupts when you are retrieving characters from a receive buffer (or writing to a transmit buffer). It is worth the extra effort to do this. There are many c code examples out there.
 

Do not use my alias in your message body when replying, your message will disappear ...

Alan
#15
m_snaeem@hotmail.com
Starting Member
  • Total Posts : 37
  • Reward points : 0
  • Joined: 2020/07/10 10:54:03
  • Location: 0
  • Status: offline
Re: Ring Buffer UART Using Harmony 2020/08/04 15:09:11 (permalink)
0
ok thanks for the help.
i would search it though my requirement requirement fullfilled but it would be worth to find more about it.
#16
Jump to:
© 2020 APG vNext Commercial Version 4.5