This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

uart flow control

Other Parts Discussed in Thread: EK-TM4C1294XL

Hi everybody!!

something can show me an example for configurate The UART in modem flow control....


Thanks

  • Hello Oscar,

    This TI Design configures the UART in hardware flow control. The function "SerialSetFlowControl" in the file "serial.c" does the necessary configuration.

    Thanks,

    Sai

  • Hello Stellaris Sai
    I am working with the TM4C129 in order to use a camera, it is comunnicated by the UART, I have already established communication with it, but my problem is when the camera take a picture and send me the dates because everypicture has 512bytes but I only can receive 16bytes... Something tell me that I can´t receive the dates becuase the FIFO receive has 16x8 bytes then I have to use the modem flow control.
    What do you think abou this???

    thanks and excuse my inconvenencia
  • Hello Oscar,

    Please provide more information so that we can help you better.

    Can you provide details about what board you are using, what TivaWare example did you start the development with?

    Also provide details about how your code is designed like are you using interrupts? A more detailed problem statement will be very valuable, like is your data being corrupted? Do you always get only the first 16 bytes or is it random?

    And finally what debug steps did you take to narrow down the problem.

    If you provide these details it will be much faster for us to help.

    Thanks,
    Sai
  • Hello Stelaris:

    First of all I am using the TM4C129NCPDT LaunchPad and I started work with CLP_Workbook so I did the examples like: Initialization, GPIO and TivaWare , PWM, SPI and QSSI and UARTas to the code, I do not use interruptions, only Iam working with polling, and I always only receive the first 16Bytes

    I send a picture which it shows how is the comunication

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/tm4c1294ncpdt.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/sysctl.h" 
    #include "driverlib/gpio.h"
    
    int o,m,g,n,p,k,delay,NoPACK;
    int F_SYNC;
    int F_ACK0;
    int F_ACK1;
    int F_ACK2;
    int F_ACK3;
    int F_ACK4;
    
    
    
    uint8_t a_ui8Syncronia[6]={0xAA,0x0D,0x00,0x00,0x00,0x00};
    uint8_t a_ui8ACK[6]={0xAA,0x0E,0x0D,0x00,0x00,0x00};
    uint8_t a_ui8Initial[6]={0xAA,0x01,0x07,0x07,0x00,0x07};
    uint8_t a_ui8SetPackageSize[6]={0xAA,0x06,0x08,0x00,0x02,0x00};
    uint8_t a_ui8Snapshot[6]={0xAA,0x05,0x00,0x00,0x00,0x00};
    uint8_t a_ui8Getpicture[6]={0xAA,0x04,0x01,0x00,0x00,0x00};
    uint8_t a_ui8Reset[6]={0xAA,0x08,0x00,0x00,0x00,0x00};
    
    uint8_t a_ui8ACK_ID[6]={0xAA,0x0E,0x00,0x00,0x00,0x00};
    
    uint8_t a_ui8ACK0[12]={0xAA,0x0E,0x0D,0x00,0x00,0x00,0xAA,0x0D,0x00,0x00,0x00,0x00};
    uint8_t a_ui8ACK1[6]={0xAA,0x0E,0x01,0x01,0x00,0x00};
    uint8_t a_ui8ACK2[6]={0xAA,0x0E,0x06,0x02,0x00,0x00};
    uint8_t a_ui8ACK3[6]={0xAA,0x0E,0x05,0x03,0x00,0x00};
    uint8_t a_ui8ACK4[6]={0xAA,0x0E,0x04,0x04,0X00,0x00};
    
    
    uint8_t RX_BUFFER0[6];
    uint8_t RX_BUFFER1[12];
    uint8_t RX_FOTO[512];
    
    UART0_INI(void){
    	SYSCTL_RCGCUART_R |=0X41; //ENABLE UART0, UART6
    	SYSCTL_RCGCGPIO_R |=0X3021; //ENABLE PORTS A,F,N,P
    	UART0_CTL_R &=~0X0001;  //DISABLE UART
    	UART0_IBRD_R =520 ; 
    	UART0_FBRD_R =53 ; 
    	UART0_LCRH_R =0X0070; //ENABLE FIFO
    	UART0_CTL_R= 0X0301 ; //ENABLE RXE, TXE AND UART
    	GPIO_PORTA_AHB_PCTL_R = 0X00000011;
    	GPIO_PORTA_AHB_AMSEL_R &= ~0X03; 
    	GPIO_PORTA_AHB_AFSEL_R |= 0X03; 
      	GPIO_PORTA_AHB_DEN_R |= 0X03; 
    }
    
    UART6_INI(void){
    	UART6_CTL_R &=~0X0001;  
    	UART6_IBRD_R =520 ; 
    	UART6_FBRD_R =53 ; 
    	UART6_LCRH_R =0X0070; 
    	UART6_CTL_R= 0X0301 ; 
    	GPIO_PORTP_PCTL_R = 0X00000011;
    	GPIO_PORTP_AFSEL_R |= 0X03; 
    	GPIO_PORTP_DEN_R |= 0X03; 
    }
    
    LED_CONFIG(void){
    	GPIO_PORTN_DEN_R=0X03;//BIT 1,0 ARE DIGITALS-N
    	GPIO_PORTN_DIR_R=0X03;//BIT 1,0 OUTPUTS
    	GPIO_PORTF_AHB_DEN_R=0X11;//BIT 4,0 ARE DIGITALS-F
    	GPIO_PORTF_AHB_DIR_R=0X11;//BIT 4,0 OUTPUTS
    }
    
    SEND_SYNC(uint8_t arrayTXS[],int g,uint8_t arrayRXS[],int m,int FlagS,int delay){
    	int i,e=0;
    	UART6_DR_R&0xFF;//CLEAR FIFO
    	UART0_DR_R&0xFF;//CLEAR FIFO
    	while(FlagS==0){
    		for(i=0;i<g;i++){
    			UART6_DR_R=arrayTXS[i];
    			
    		}
    		SysCtlDelay(delay);
    		while(((UART6_FR_R&0X0010)==0)&&(e==0)){
    			arrayRXS[0]=UART6_DR_R&0xFF;
    			if(arrayRXS[0]==0xAA){
    				UART0_DR_R=arrayRXS[0];//PRINT IN TERMINAL
    				FlagS=1;
    				e=1;
    			}
    		}
    	}
    }
    
    
    RECEIVE_SYNC(uint8_t arrayDS[],int o){
    	int t=1;
    	while(t<o){
    		if((UART6_FR_R&0x0010)==0){
    			arrayDS[t]=UART6_DR_R&0xFF;
    			UART0_DR_R=arrayDS[t++];
    		}
    	}
    }
    
    
    SEND_COMMANDS(uint8_t arrayTX[],int k,int Flag,int delay)
    {
    	UART6_DR_R&0xFF;//CLEAR FIFO
    	while(Flag==1){
    		int i;
    		for(i=0;i<k;i++){
    			UART6_DR_R=arrayTX[i];
    		}
    		Flag=0;
    	}
    	SysCtlDelay(delay);
    }
    
    RECEIVE_COMMANDS(uint8_t arrayRX[],int o){
    	int t=0;
    	while(t<o){
    		//UART0_DR_R&0xFF;
    		while((UART6_FR_R&0x0010)!=0);
    		arrayRX[t]=UART6_DR_R&0xFF;
    		UART0_DR_R=arrayRX[t++];
    	}
    }
    
    int VERIFY_COMMANDS(uint8_t arrayRXV[],int m,uint8_t arrayD[],int g,int Flag){
    	int c;
    		for(c=0;c<m;c++){
    			if(arrayRXV[c]==arrayD[c]){
    				g--;
    			}
    		}
    		if(g==0){
    			Flag=1;
    		}
    return Flag;
    }
    
    RECEIVE_FOTO(uint8_t arrayRX[],int o){
    	int t=0;
    	while((UART6_FR_R&0x0040)==1);
    	while(t!=o){
    		if((UART6_FR_R&0x0010)==0){
    			arrayRX[t++]=UART6_DR_R&0xFF;
    		}
    	}
    }
    
    int CALCULATE_NUMBER_PACK(){                                                                      
    	uint32_t SizeImg,P4,P3,P2,NoPACK,SizePak=0;
    	SizePak=0x0200;
    	P4 = RX_BUFFER1[11]<<16;
    	P3 = RX_BUFFER1[10]<<8;
    	P2 = RX_BUFFER1[9];
    	SizeImg = P4 | P3 | P2;
    	NoPACK = SizeImg/(SizePak-6);
    return NoPACK;
    }
    
    int main(){
    	uint32_t g_ui32SysClock;
    	g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
    	int NoACK=0;
    	UART0_INI();
    	UART6_INI();
    	LED_CONFIG();
    	GPIO_PORTN_DATA_R=0x00;//CLEAN PORT N
    	GPIO_PORTF_AHB_DATA_R=0x00;//CLEAN PORT F
    	SysCtlDelay(40000000);
    
    //====================================================================
    	SEND_SYNC(a_ui8Syncronia,6,RX_BUFFER1,12,F_SYNC,44800000);
     	RECEIVE_SYNC(RX_BUFFER1,12);
    	F_ACK0= VERIFY_COMMANDS(RX_BUFFER1,12,a_ui8ACK0,12,F_ACK0);//VERIFY_SYNC*/
    //====================================================================
    	SEND_COMMANDS(a_ui8ACK,6,F_ACK0,44800000);// SEND_ACK
    	SEND_COMMANDS(a_ui8Initial,6,F_ACK0,2000000);// SEND_INITIAL; 
    	GPIO_PORTN_DATA_R  ^=0X02;//SWITCH ON LED N1
    	RECEIVE_COMMANDS(RX_BUFFER0,6);//RECEIV_ACK-1
    	F_ACK1= VERIFY_COMMANDS(RX_BUFFER0,6,a_ui8ACK1,6,F_ACK1);//VERIFY_ACK-1;
    	SEND_COMMANDS(a_ui8SetPackageSize,6,F_ACK1,44800000);//SEND_PACKAGE_SIZE
    	GPIO_PORTN_DATA_R  ^=0X01;//SWITCH ON LED N0
    	RECEIVE_COMMANDS(RX_BUFFER0,6);//RECEIV_ACK-2
    	F_ACK2= VERIFY_COMMANDS(RX_BUFFER0,6,a_ui8ACK2,6,F_ACK2);//VERIFY_ACK-2
    	SEND_COMMANDS(a_ui8Snapshot,6,F_ACK2,44800000);//SEND_SNAPSHOT
    	GPIO_PORTF_AHB_DATA_R  ^=0X10;//SWITCH ON LED F4
    	RECEIVE_COMMANDS(RX_BUFFER0,6);//RECEIVE_ACK-3
    	F_ACK3= VERIFY_COMMANDS(RX_BUFFER0,6,a_ui8ACK3,6,F_ACK3);//VERIFY_ACK-3
    	SEND_COMMANDS(a_ui8Getpicture,6,F_ACK3,44800000);//SEND_GET_PICTURE*/
    	GPIO_PORTF_AHB_DATA_R  ^=0X01;//SWITCH ON LED F0
    	RECEIVE_COMMANDS(RX_BUFFER1,12);//RECEIVE_ACK-4 and DATA LENGTH
    	F_ACK4= VERIFY_COMMANDS(RX_BUFFER1,12,a_ui8ACK4,6,F_ACK3);//VERIFY_ACK-3
    //====================================================================
    	NoPACK= CALCULATE_NUMBER_PACK();
    	NoACK= NoPACK+1;
    //====================================================================
    	SEND_COMMANDS(a_ui8ACK_ID,6,F_ACK4,44800000);
    	RECEIVE_FOTO(RX_FOTO,512);
    
    while (1);
    }
    
    
    

    Can you see in the picture, the protocol is easy, because I send comands and receive comands..


    Thanke you very much..........

  • Iam sorry, I sent my code................ I can not sent the picture
  • This is the protocol of Transmition 

  • Hello Oscar,

    I tried to understand you code, but it is very hard to follow, as you have used DRMs in your code. The use of DRMs is not recommended as it is very hard to understand, debug and maintain. Few months from now, even you might find it hard to understand what a particular line does.

    Using TivaWare APIs is a better approach, not only because it makes the code easy to read, debug and maintain; but also because most of the drivers are in use since a long time and hence are better tested (and hopefully lesser bugs) than the driver you write from scratch.

    "uart_echo" in the folder "<TivaWare_Install_Directory>/examples/ek-tm4c1294xl/uart_echo" is a good code to start your development. Note that this example uses UART Receive Interrupts. If you don't wish to work with interrupts, you can remove them.

    Hopefully the issue you are facing might be solved once you start using TivaWare APIs.

    Thanks,
    Sai