0

**Is there a way for connecting 4 microcontrollers together using UART even if it has one UART module in each one of them(18f452) to send data from three of them to the master(18f4550) for display it on a pc

switching using and gates Img

microcontrollers with uart conn Img

The mikroC Code for the master UC "U4"

   // LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
char u1[20], u2[20], u3[20];
void newline()
{
  Uart1_write (0x0D);
  Uart1_write (0x0A);
}
void main() {
  TRISD = 0x00;
  Uart1_Init(9600);
  delay_ms(20);                  // Wait for UART module to stabilize

  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
while(1){
  portd=0x01;
  UART1_Read_Text(u1, "ok", 20);
  portd=0x02;
  UART1_Read_Text(u2, "OK", 20);
  portd=0x04;
  UART1_Read_Text(u3, "OK", 20);
  Lcd_Out(1,5,u1);
  Delay_ms(1000);
  Lcd_Out(1,5,u2);
  Delay_ms(1000);
  Lcd_Cmd(_LCD_CLEAR);
  Delay_ms(1000);
  Lcd_Out(1,5,u3);
  delay_ms(250);       
  portd=0x08;
UART1_Write_Text(u1);
        newline();
        newline();
UART1_Write_Text(u2);
        newline();
        newline();
UART1_Write_text(u3);
        newline();
        newline();   
  }
}

the mikroC Code for the slaves

char txt[20];
int Vin;
float Dis_volt;
void main()
{
     TRISA = 0xFF;
     ADCON1 = 0x80;
     uart1_Init (9600);
     while(1)
      {
      Vin = adc_read(0);
      Dis_volt = (Vin * 500)/ 1024;
      floatToStr (Dis_volt , txt);
      txt[5]='o';
      txt[6]='k';
      Uart1_write_Text(txt);
     }
}
vader
  • 889
  • 8
  • 22
Kakorotto
  • 1
  • 1
  • If your UARTs are open-drain you can connect everything (all TX with all RX lines together). Then, you need some smart coding and token-ring approach to make things work. – tonypdmtr Feb 12 '19 at 21:45
  • you can daisy chain them in a circle, tx of 0 goes to rx of 1 tx of 1 goes to rx of 2...something like RS-485 though is already meant for this. I assume like RS-232 RS-485 is an electrical and maybe pinout spec not a protocol spec so you will still need to figure out who can talk when to avoid stomping on others. – old_timer Feb 12 '19 at 22:41
  • You should not try to connect more than one UART to another using TTL signals or RS-232 transceivers. Instead use RS-485 transceivers, which are intended for multidrop configuration. – sawdust Feb 13 '19 at 01:05

0 Answers0