Shop OBEX P1 Docs P2 Docs Learn Events
Using any pin in Atmega32 as RxD — Parallax Forums

Using any pin in Atmega32 as RxD

Gaurav GuptaGaurav Gupta Posts: 1
edited 2012-09-05 10:05 in Accessories
I have used the USART function to activate the inbuilt TxD and RxD pins in ATMEGA32. But i have to use two recievers in the same chip. How do i do that?

Comments

  • LeonLeon Posts: 7,620
    edited 2012-07-10 03:07
    Use a software UART.
  • SteelSteel Posts: 313
    edited 2012-09-05 10:05
    I bit-bang UARTS if I need more. (firmware fix) It takes some testing and some timing work but once I get it, it is pretty dang valuable:

    You are essentially creating a serial-to-parallel pattern by doing the following:

    -Make note of what pin is the UART_Rx
    -Set pin as input
    -Set interrupt for falling edge detection. If that is not available for that pin, then set the interrupt to trigger on a "low" state.
    -Create a "Rx_Port_mask" register
    -Create a "Rx_Byte" register

    In the interrupt, do the following:
    -wait x microseconds (based on baudrate) / 2. This puts you at the midpoint of the Start Bit.
    -Verify pin state is still low. (Start bit is a low pin for x microseconds)
    -If the pin is still low, that means there is a "real" start bit from a message coming to the pin.

    Repeat the following 8 times to recieve the byte being sent:
    -wait x microseconds (based on baudrate). Puts you about the center of data bit
    -Read Port State. Move the value of the port to your Rx_port_mask register.
    -Mask out port except for the pin in which you are using as your uart. (AND the port with 0x00001000...in which the "1" is the pin that is your UART Rx.)
    -OR the Rx_Byte register with the Rx_port_mask register
    -Roll Left the Rx_Byte register **I forget if UART is MSB or LSB First. The roll direction is based on which bit is first.

    Your Rx_Byte register will now contain the byte transferred, but the bits will be shifted based on what pin is the RX pin.
    -Shift the register until the MSB of the shifted byte is in Bit7 of the register and the LSB is in Bit0.
    -Move the content of the RX_Byte register into a buffer in which you can store multiple bytes.

    Again, it may be confusing...but it is definately able to be done.
Sign In or Register to comment.