remap port pin

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

uc = Xmega32E5, I try to change USART TXD0 from  from pin PD3 to pin PD7 and back, no success, tx stays all the time

at same pin which is first selected

my code:

while(1)
{
.
.
        printf("%s\r\n\0", rx_array3);
        PORTD.REMAP=(0<<PORT_USART0_bp) | (0<<PORT_TC4D_bp) | (0<<PORT_TC4C_bp) | (0<<PORT_TC4B_bp) | (0<<PORT_TC4A_bp);
        printf("%s\r\n\0", rx_array1);
        PORTD.REMAP=(1<<PORT_USART0_bp) | (0<<PORT_TC4D_bp) | (0<<PORT_TC4C_bp) | (0<<PORT_TC4B_bp) | (0<<PORT_TC4A_bp);
}        

ana

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
// PORTD Peripheral Output Remapping
// USART0 XCK: Pin 1
// USART0 RXD: Pin 2
// USART0 TXD: Pin 3
PORTD.REMAP=(0<<PORT_USART0_bp) | (0<<PORT_TC4D_bp) | (0<<PORT_TC4C_bp) | (0<<PORT_TC4B_bp) | (0<<PORT_TC4A_bp);


// PORTD Peripheral Output Remapping
// USART0 XCK: Pin 5
// USART0 RXD: Pin 6
// USART0 TXD: Pin 7
PORTD.REMAP=(1<<PORT_USART0_bp) | (0<<PORT_TC4D_bp) | (0<<PORT_TC4C_bp) | (0<<PORT_TC4B_bp) | (0<<PORT_TC4A_bp);

This  is what the Codevision Wizard produces.     I don't have a 32E5.   So I can't try it for myself.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have similar commands in my code but those don't change tx pins, should I do something else also.

I have tried delay after change, couldn't find anything from datasheet

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would try to wait for tx buffer empty, disable rx/tx, write the REMAP register, and then reconfigure the USART.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

just tried this on an ATXMega8E5 and it appears to work fine (no delay needed)

can't see anything obviously different to what you have shown

I do set both Tx pins to output

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah-ha.   I can get at PC0-PC3 and PC1-PC7 on my 32A4U "shield".

 

So I can try remapping the USARTC0 on a 32A4U.

I will let you know if it works.

// USART0 XCK: Pin 5
// USART0 RXD: Pin 6
// USART0 TXD: Pin 7
// SPI MOSI: Pin 5
// SPI SCK: Pin 7
PORTC.REMAP=(0<<PORT_SPI_bp) | (1<<PORT_USART0_bp) | (0<<PORT_TC0D_bp) | (0<<PORT_TC0C_bp) | (0<<PORT_TC0B_bp) | (0<<PORT_TC0A_bp);

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mbarton wrote:

just tried this on an ATXMega8E5 and it appears to work fine (no delay needed)

can't see anything obviously different to what you have shown

I do set both Tx pins to output

 

I have to check again, if XMega8E5 works XMega32E5 should work also.

My goal change tx pin about 10 times/s (PD3, PD7, PD3, PD7, ....)

Pin is checked by oscilloscope

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found some time to do a short test on a XMega32E5.

#include <avr/io.h>
#include <util/delay.h>

// 9600 baud @2MHz
#define BAUD_VALUE 1539
#define BAUD_SCALE -7

void usartD0_init(void)
{
    PORTD.DIRSET = PIN3_bm | PIN7_bm;
    PORTD.OUTSET = PIN3_bm | PIN7_bm;

    USARTD0.CTRLC = USART_CHSIZE_8BIT_gc | USART_PMODE_DISABLED_gc;

    USARTD0.BAUDCTRLA = (uint8_t) BAUD_VALUE;
    USARTD0.BAUDCTRLB = (BAUD_SCALE << USART_BSCALE0_bp) | (BAUD_VALUE >> 8);

    USARTD0.CTRLB |= USART_TXEN_bm;
}

void usartD0_remap(uint8_t remap)
{
    while ((USARTD0.STATUS & USART_DREIF_bm) == 0)
        ;
    // Wait for 12 bit times to make sure any pending data has been sent.
    // We could check the TXCIF flag, but it isn't set if no data have been sent
    _delay_us(1000000*12/9600);
    
    USARTD0.CTRLB &= ~USART_TXEN_bm;
 
    if (remap)
        PORTD.REMAP |= PORT_USART0_bm;
    else
        PORTD.REMAP &= ~PORT_USART0_bm;

    // This line seems to be important?!
    PORTD.DIRSET = PIN3_bm | PIN7_bm;

    USARTD0.CTRLB |= USART_TXEN_bm;
}

void usartD0_putc(char c)
{
    while ((USARTD0.STATUS & USART_DREIF_bm) == 0)
        ;
    USARTD0.DATA = c;
}

int main(void)
{
    usartD0_init();

    while(1)
    {
        usartD0_remap(0);
        usartD0_putc('0');
        usartD0_remap(1);
        usartD0_putc('1');
    }
}

Last Edited: Fri. Nov 28, 2014 - 08:59 AM