Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] UART code for flowcontrol enable

Status
Not open for further replies.

rajalakshmiA

Newbie level 6
Joined
Jun 23, 2015
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
130
Hi
I am using PI32MX795f512l .. I want to integrate flowcontrol in my uart communication .. As of now i am using only TX and RX pins for data transmit and receive ...
In Continous transmission ,in bluetooth module i am getting overwritten buffer...Pls Help me to come out of this.. I am new one to this.... How to enable flowcontrol in my uart code. Here i have attached my code below


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1
#define SYS_FREQ (80000000L)
#pragma config ICESEL = ICS_PGx1
 
void init_uart()
{
    UARTConfigure(UART_MODULE_ID, UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(UART_MODULE_ID, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(UART_MODULE_ID, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    UARTSetDataRate(UART_MODULE_ID, GetPeripheralClock(), DESIRED_BAUDRATE);
    UARTEnable(UART_MODULE_ID, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
}
void Uart_Interrupt(){
INTEnable(INT_SOURCE_UART_RX(UART_MODULE_ID), INT_ENABLED);
    INTSetVectorPriority(INT_VECTOR_UART(UART_MODULE_ID), INT_PRIORITY_LEVEL_2);
    INTSetVectorSubPriority(INT_VECTOR_UART(UART_MODULE_ID), INT_SUB_PRIORITY_LEVEL_0);
 
    // Enable multi-vector interrupts
    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
    INTEnableInterrupts();
}
main()
{
   init_uart();
   Uart_Interrupt();
   while(1){
    if(flag ==1){ // some code}
   }
   
}
void __ISR(_UART2_VECTOR,IPL2) IntUart2Handler(void)
{
    unsigned char Receivedchar;
    if(INTGetFlag(INT_SOURCE_UART_RX(UART_MODULE_ID)))
    {
        Receivedchar= UARTGetDataByte(UART_MODULE_ID);
        ReceivedByte[buf]=Receivedchar;
        buf++;
        count++;
        flag=1;
        INTClearFlag(INT_SOURCE_UART_RX(UART_MODULE_ID));
 
    }
        
   // We don't care about TX interrupt
    if ( INTGetFlag(INT_SOURCE_UART_TX(UART_MODULE_ID)) )
    {
        INTClearFlag(INT_SOURCE_UART_TX(UART_MODULE_ID));
    }
}

 
Last edited by a moderator:

Hi,

did you read documents about UART software flow control?

***
Check: (to avoid software flow control)
* if reducing / increasing the baud rate may solve your problem
* if the receiver software could be optimized to avoid buffer overflow. (latency times, buffer size)

Klaus
 

To start with, flowcontrol from a microcontroller is not really complex. There are two flow control models usually: hardware and software.

For hardware, the sender asserts RTS (request to send). The receiver responds with CTS (clear to send). In principle, you could use a pair of GPIO pins for RTS/CTS signals. I did not see the uC datasheet myself. But, in ideal scenario, the RTS should have peripheral input interrupt enabled on it. Here is a rough algoirthm:

=============================================
On RTS Assert (or Interrupt):
if (buffer full):
continue # The device holds the data in its buffer.
else
assert CTS
get a byte

On receive byte (or Interrupt):
if (buffer full):
de-assert CTS
=========================================

The software flow control uses a pair of control characters - XON/XOFF. Search around for software flow control in, say, Google.

I would start with datasheets. If the baudrate could be reduced, that'll be a very good place to start. The primary requirement in any case is: the sending device must support flow control - either software or hardware.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top