• AVR Freaks

Hot!Problem During Communication Between Two Microcontrollers Via Uart2

Author
poross
New Member
  • Total Posts : 11
  • Reward points : 0
  • Joined: 2020/05/21 04:21:18
  • Location: 0
  • Status: offline
2020/07/12 23:52:55 (permalink)
0

Problem During Communication Between Two Microcontrollers Via Uart2

Hi,
I am a newcomer to the PIC32mx and XC32.  I am using XC32 v2.41, MPLABX v5.40, and two pic32mx570f512l.  I want to make a cable tester.  It will have 50 pins for output data and 50 pins for input data.  
my code is for output data;
typedef struct output_pin_description {
  volatile uint32_t * lat;
  int mask;
} op;
 
op opins[32] = {
  { &LATD, 0x0400 },//pin2
  { &LATD, 0x0200 },
  { &LATD, 0x0010 },
  { &LATD, 0x0020 },//pin3
  { &LATD, 0x0040 }///pin4
  
};
 
void pin_high(int no) {
    
  *(opins[no].lat) |= opins[no].mask;
}

void pin_low(int no) {
  *(opins[no].lat) &= ~opins[no].mask;
}

int main(void)
{
     __XC_UART = 1;
   
    // initialize the device
    SYSTEM_Initialize();
    int temp=0;
    int i=0;
    int j=1;
    int send=1;
        
    while (1)
    {
        send=1;
        for (i = 0; i < 5; i++)
        {
            pin_high(i);
           
            UART2_Write(send);
             delay_ms(1000);
            while(temp!=send)
            {
                temp= UART2_Read();
            }
            send=send<<1;
            pin_low(i);
           
        }
     }
    return -1;
}

 my code is for reading input data and write pc;
int main(void)
{
     __XC_UART = 1;
   
    // initialize the device
    SYSTEM_Initialize();
    int temp=0;
    int i=0;
    int j=1;
    int POS5_1,POS5_2,POS5_3,POS5_4,POS5_5,POS5=0;
    printf("start\r\n");
    while (1)
    {
        j=1;
        for(i=0; i<5; i++)
        {
            while(temp!=j)
            {
                temp= UART2_Read();
            }
            
            POS5_1=IO_RF1_GetValue();
            POS5_2=IO_RD4_GetValue()<<1;
            POS5_3=IO_RD13_GetValue()<<2;
            POS5_4=IO_RD12_GetValue()<<3;
            POS5_5=IO_RD3_GetValue()<<4;
            POS5=POS5_1+ POS5_2+POS5_3+POS5_4+POS5_5;
                
            if(POS5==temp)
            {
                printf("%d.pin, received %d ,read %d true\r\n",i+1,temp,POS5);
            }
            else
            {
                printf("%d.pin, received %d,read %d false\r\n",i+1,temp,POS5);
            }
        delay_ms(1000);
        UART2_Write(j);
        j=(j<<1);
        }
    }
    return -1;
}

 
My project output:
1.pin, received 1, read 1 true
2.pin, received 2, read 2 true
3.pin, received 4, read 4 true
4.pin, received 8, read 8 true
5.pin, received 16, read 16 true

Synchronization is impaired after some time or microprocessors are not waiting for each other
1.pin, received 1, read 2 false
2.pin, received 2, read 4 false
3.pin, received 4, read 8 false
4.pin, received 8, read 16 false
5.pin, received 16, read 1 false
....
....
...
1.pin, received 1, read 4 false
2.pin, received 2, read 8 false
3.pin, received 4, read 16 false
4.pin, received 8, read 1 false
5.pin, received 16, read 2 false

 
 
post edited by poross - 2020/07/12 23:55:09
#1

0 Replies Related Threads

    Jump to:
    © 2020 APG vNext Commercial Version 4.5