0

I'm trying to send a number in binary from one Arduino atmega328p to another using USART and then use the received data to display it on a seven segments display (7seg-mpx1-cc) here is the code on the sender part:

.INCLUDE "m328pdef.inc"
.ORG 0X00

// Intialize USART
SBI DDRD,1 // Set Tx pin as output
LDI R17,0
STS UBRR0H, R17
LDI R17, 0X67
STS UBRR0L, R17

// Enable transmitter
LDI R17,0X08
STS UCSR0B, R17 

MAIN:
  // Wait for the transmit buffer to be empty
  LDS R17, UCSR0A
  SBRS R17, UDRE0
  RJMP MAIN

  // Transmit the 6 with a delay between each letter
  LDI R18, 0b11111110
  STS UDR0,R18
  CALL DELAY


HERE:
  RJMP HERE

DELAY:
  LDI R20, 30

DELAY_LOOP_1:
  LDI R21,30

DELAY_LOOP_2:
  LDI R22,30

DELAY_LOOP_3:
  DEC R22
  NOP 
  BRNE DELAY_LOOP_3

  DEC R21
  BRNE DELAY_LOOP_2

  DEC R20
  BRNE DELAY_LOOP_1
  RET


here is the code at the receiver part:


.INCLUDE "m328pdef.inc"
.ORG 0X00

// set portC at output
LDI R16 , 0xFF
out DDRB , R16

// Intialize USART
SBI DDRD,0 // Set Rx pin as input
LDI R17,0
STS UBRR0H, R17
LDI R17, 0X67
STS UBRR0L, R17
LDI R17, 0X06 
STS UCSR0C, R17

// Enable receiver and receive interrupt
LDI R17, 0X90
STS UCSR0B, R17

// Enable global interrupts
SEI

MAIN:
  // Wait for data to be received
  LDS R17, UCSR0A
  SBRS R17, RXC0
  RJMP MAIN

  // Read the received data from the receive buffer
  LDS R17, UDR0

  // Output the received data to Port C
  out PORTB , R17

  RJMP MAIN




delay:
    
    
    LDI R16 , 200
    loop1:
        LDI R17 , 30
        loop2:
            LDI R19 , 30
            loop3:
                nop
                dec R19
            BRNE loop3
            dec R17
        BRNE loop2
        dec R16
    BRNE loop1
RET



here is the circuit connection but as you can see both RX TX are acting like inputs Circuit

what should I do to fix it?

any help is appreciated, thanks.

hcheung
  • 3,377
  • 3
  • 11
  • 23

0 Answers0