+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Newbie level 6
    Points: 172, Level: 2

    Join Date
    Dec 2015
    Posts
    11
    Helped
    1 / 1
    Points
    172
    Level
    2

    8051 Serial Communication - Data is sent once but received repeatedly

    I am trying to interface my PC with 8051 using a CP2102 USB to UART bridge. I tried sending the characters 'M' & 'C' and view them using hyper terminal. I am able to receive the characters but instead of receiving them once, the data is received repeatedly in a loop fashion. I simulated this in Proteus and it works as expected i.e. I'm getting characters MC and them the program halts in while loop. Same results as proteus in Keil Debug as well. Please help me fix this issue.


    Code:
    #include 
    void delay_us(unsigned int d);
    void send(unsigned char x);
    void main(void)
    {
    TMOD=0x20;
    TH1=0xFD;
    SCON=0x50;
    	TR1=1;
    	RI=0;
    	TI=0;
    	 send('M');
    	delay_us(1000);
    	send('C');
    while(1){
    
    
    	
      }
    }
    
    
    void delay_us(unsigned int d)
    {
       unsigned int i, limit;
       limit = d/15;
    
       for(i=0;i
    
    Click image for larger version. 

Name:	8051SerialSimulation.PNG 
Views:	12 
Size:	72.8 KB 
ID:	124558

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 3
    Points: 3,996, Level: 14

    Join Date
    Aug 2015
    Posts
    773
    Helped
    142 / 142
    Points
    3,996
    Level
    14

    Re: 8051 Serial Communication - Data is sent once but received repeatedly

    Maybe MCU is resetting and restarting.


    1 members found this post helpful.

  3. #3
    Advanced Member level 3
    Points: 3,996, Level: 14

    Join Date
    Aug 2015
    Posts
    773
    Helped
    142 / 142
    Points
    3,996
    Level
    14

    Re: 8051 Serial Communication - Data is sent once but received repeatedly

    Add

    Code:
    P3 = 0x03;



    •   AltAdvertisement

        
       

  4. #4
    Newbie level 6
    Points: 172, Level: 2

    Join Date
    Dec 2015
    Posts
    11
    Helped
    1 / 1
    Points
    172
    Level
    2

    Re: 8051 Serial Communication - Data is sent once but received repeatedly

    Turns out the circuit I was working on has a DS1232 WDT & it was resetting the controller.Thank you for the quick response!



  5. #5
    Full Member level 3
    Points: 1,592, Level: 9
    pradhan.rachit's Avatar
    Join Date
    Oct 2013
    Location
    Mumbai
    Posts
    161
    Helped
    22 / 22
    Points
    1,592
    Level
    9

    Re: 8051 Serial Communication - Data is sent once but received repeatedly

    Quote Originally Posted by praveenrpk92 View Post
    Turns out the circuit I was working on has a DS1232 WDT & it was resetting the controller.Thank you for the quick response!
    Could you find out why the WDT was resetting?



  6. #6
    Newbie level 6
    Points: 172, Level: 2

    Join Date
    Dec 2015
    Posts
    11
    Helped
    1 / 1
    Points
    172
    Level
    2

    Re: 8051 Serial Communication - Data is sent once but received repeatedly

    ST pin(7) of DS1232 has to be driven from high to low state within the WDT time-out period(150 ms) or else it would reset the controller. ST pin is connected to my micro-controller at PORT 1 pin 0 , so I simply had to make it HIGH at the beginning of the while loop & LOW at the end.


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  7. #7
    Newbie level 1
    Points: 16, Level: 1

    Join Date
    Dec 2015
    Posts
    1
    Helped
    0 / 0
    Points
    16
    Level
    1

    Re: 8051 Serial Communication - Data is sent once but received repeatedly

    Hi Praveen,

    You can use below code & check:

    Code:
    #include 
    #include 
    
    void init()     // Initialize Timer 1 for serial communication
    {
    TMOD=0x20;  //Timer1, mode 2, baud rate 9600 bps
    TH1=0XFD;
    SCON=0x50;
    TR1=1;
    }
    
    void recieve()  //Function to receive serial data
    {
    unsigned char value;
    while(RI==0);
    value=SBUF;
    P1=value;
    RI=0;
    }
    
    void transmit()  // Funtion to transmit serial data
    {
    P2=P1-32;
    SBUF=P2;
    while(TI==0);
    TI=0;
    }
    
    void main()
    {
    while(1)
    {
      init();
      recieve();
      transmit();
    }
    }

    Image of Proteus Simulation for your reference:
    Last edited by alexan_e; 30th December 2015 at 09:46. Reason: added CODE tags, removed promotional link



--[[ ]]--