This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMDSRM48HDK: Can't receive data from SCI/LIN(from PC via XDS100v2 USB JTAG emulator)

Part Number: TMDSRM48HDK
Other Parts Discussed in Thread: HALCOGEN

Hi, I'm new to embedded programming, so I'm sorry if I'm missing something very obvious.

I'm currently using TMDSRM48HDK to learn embedded programming and following below tutorial. (Hercules How to Tutorial: Using the SCI for UART Communication | TI.com Video) While my program will send data from the board to pc successfully, it does not receive data from PC. 

Main function initialize sci, send and receive data.

static uint8_t command = 0;
int main(void)
{
/* USER CODE BEGIN (3) */
    sciInit();
    sciSend(scilinREG, 13, "Press a key\r\n");
    sciReceive(scilinREG, 1, &command);
    while(1){}
/* USER CODE END */

    return 0;
}

 

sciNotification simply echoes what it receives(at least it is supposed to do so).

/* USER CODE BEGIN (4) */
void sciNotification(sciBASE_t *sci, uint32_t flags){
    sciSend(sci, 1, &command);
    sciReceive(sci, 1, &command);
}

void esmGroup1Notification(int bit){}

void esmGroup2Notification(int bit){}

/* USER CODE END */

 

SCI Configuration is from HalCoGen and since I didn't touch them they shouldn't be anything crazy.

void sciInit(void)
{
/* USER CODE BEGIN (2) */
/* USER CODE END */


/** @b initialize @b SCILIN */

/** - bring SCI out of reset */
    scilinREG->GCR0 = 0U;
    scilinREG->GCR0 = 1U;

/** - Disable all interrupts */
    scilinREG->CLEARINT = 0xFFFFFFFFU;
    scilinREG->CLEARINTLVL = 0xFFFFFFFFU;

/** - global control 1 */
    scilinREG->GCR1 = (uint32)((uint32)1U << 25U) /* enable transmit */
        | (uint32)((uint32)1U << 24U) /* enable receive */
        | (uint32)((uint32)1U << 5U) /* internal clock (device has no clock pin) */
        | (uint32)((uint32)(2U-1U) << 4U) /* number of stop bits */
        | (uint32)((uint32)0U << 3U) /* even parity, otherwise odd */
        | (uint32)((uint32)0U << 2U) /* enable parity */
        | (uint32)((uint32)1U << 1U); /* asynchronous timing mode */

/** - set baudrate */
    scilinREG->BRS = 650U; /* baudrate */

/** - transmission length */
    scilinREG->FORMAT = 8U - 1U; /* length */

/** - set SCI pins functional mode */
    scilinREG->PIO0 = (uint32)((uint32)1U << 2U) /* tx pin */
        | (uint32)((uint32)1U << 1U); /* rx pin */


/** - set SCI pins default output value */
    scilinREG->PIO3 = (uint32)((uint32)0U << 2U) /* tx pin */
        | (uint32)((uint32)0U << 1U); /* rx pin */


/** - set SCI pins output direction */
    scilinREG->PIO1 = (uint32)((uint32)0U << 2U) /* tx pin */
        | (uint32)((uint32)0U << 1U); /* rx pin */


/** - set SCI pins open drain enable */
    scilinREG->PIO6 = (uint32)((uint32)0U << 2U) /* tx pin */
        | (uint32)((uint32)0U << 1U); /* rx pin */


/** - set SCI pins pullup/pulldown enable */
    scilinREG->PIO7 = (uint32)((uint32)0U << 2U) /* tx pin */
        | (uint32)((uint32)0U << 1U); /* rx pin */


/** - set SCI pins pullup/pulldown select */
    scilinREG->PIO8 = (uint32)((uint32)1U << 2U) /* tx pin */
        | (uint32)((uint32)1U << 1U); /* rx pin */


/** - set interrupt level */
    scilinREG->SETINTLVL = (uint32)((uint32)0U << 26U) /* Framing error */
        | (uint32)((uint32)0U << 25U) /* Overrun error */
        | (uint32)((uint32)0U << 24U) /* Parity error */
        | (uint32)((uint32)0U << 9U) /* Receive */
        | (uint32)((uint32)0U << 8U) /* Transmit */
        | (uint32)((uint32)0U << 1U) /* Wakeup */
        | (uint32)((uint32)0U); /* Break detect */

/** - set interrupt enable */
    scilinREG->SETINT = (uint32)((uint32)0U << 26U) /* Framing error */
        | (uint32)((uint32)0U << 25U) /* Overrun error */
        | (uint32)((uint32)0U << 24U) /* Parity error */
        | (uint32)((uint32)1U << 9U) /* Receive */
        | (uint32)((uint32)0U << 1U) /* Wakeup */
        | (uint32)((uint32)0U); /* Break detect */

/** - initialize global transfer variables */
    g_sciTransfer_t[1U].mode = (uint32)0U << 8U;
    g_sciTransfer_t[1U].tx_length = 0U;
    g_sciTransfer_t[1U].rx_length = 0U;

/** - Finaly start SCILIN */
    scilinREG->GCR1 |= 0x80U;

/* USER CODE BEGIN (3) */
/* USER CODE END */
}

HalCoGen version is 04.06.00 and CCS version is 7.3.0.00019. I'm using CCS built-in terminal to communicate with board. Baud rate, data bits etc probaby aren't the problem because board to pc communication(sciSend) works very well. Board is connected with USB Type B at J16 to PC with USB 2.0 Type A. When I type anything in terminal SCIRX LED on board blinks, so data is definitely going in. But when I tried below code in main

while(1){
    if(val != scilinREG->RD){
        sciSend(scilinREG, 9, "changed\r\n");
        val = scilinREG->RD;
    }
}

it didn't print anything so probably nothing was going into SCI register. Setting breakpoint at sciNotification did nothing either.

I'd be glad to have any advice. Thanks in advance!

  • Hello Yejung,

    To use SCI interrupt for receiving character, you need to enable the interrupt first:

    1. Enable IRQ in CPU level: The ARM CPU provides two vectors for interrupt requests—fast interrupt requests (FIQs) and normal interrupt requests (IRQs). FIQs are higher priority than IRQs, and FIQ interrupts may interrupt IRQ interrupts. After reset (power reset or warm reset), both FIQ and IRQ are disabled. The CPU may enable these interrupt request channels individually within the CPSR (Current Program Status Register).

        call of of the following function in your main() to enable interrupt:

        _enable_IRQ();  --> enable IRQ

        or 

        _enable_interrupt_();  --> enable FIQ and IRQ

    2. Check the SCI channel in VIM table:

    3. Enable interrupt in peripheral level:

    Interrupt generation begins when an event occurs within a peripheral module. But the interrupt is not always generated when an event occurs, the peripheral must make an interrupt request to the VIM based on the event occurrence. The peripheral contains an interrupt enable bit to control whether the event occurrence causes an interrupt request to the VIM.

         

    The interrupt priority level in #2 an #3 should be consistent: high or low.

  • Hi Wang, thanks for your response.

    I checked my code and HalCoGen settings out. It turns out that I set LIN1 High channel in VIM table and receive interrupt in peripherals correctly, but I didn't call _enable_interrupt_ so I included calling _enable_interrupt_(). (CCS could not find symbol _enable_IRQ. It might be for some other system or obsolete?)

    Unfortunately, receive interrupt still does not work. It might be worth noting though that when I enabled both TX interrupt and RX interrupt, linHighLevelInterrupt was generated without problem when transmitting.

    Can there be any other cause of the problem? I'm almost beginning to think if my board is damaged...

  • Hello,

    The _enable_IRQ() is one of the compiler Intrinsics. 

  • Hello,

    Can you please double check SCI register setting to make sure the SET RX INT bit of SETINT register is set? After you type a character in Terminal, is any bit in FLG register and INTVECT0 set?

  • Hi Wang,

    I added below code to main loop and set breakpoint in all 3 if blocks so that program will pause when something changes.

    while(1){
        temp = scilinREG->SETINT;
        if(setint != temp){
            setint = temp;
        }
        temp = scilinREG->FLR;
        if(flr != temp){
            flr = temp;
        }
        temp = scilinREG->INTVECT0;
        if(intvect0 != temp){
            intvect0 = temp;
        }
    }

    SETINT is 512(0x200), SET RX INT : only rx interrupt is enabled(I disabled tx interrupt in HalCoGen).

    FLR is 2308(0x904), TX EMPTY / TX RDY / IDLE.

    INTVECT0 is 0.

    Writing anything into terminal does nothing and none of those 3 values change. But I noticed that IDLE flag is set, of which technical reference manual describes that SCI receiver is not in idle state and SCI will not receive any data.

    Could this be the source of the problem?

  • Please see the example in this thread:

  • Hi Wang,

    Even after using suggested example sciNotification is still not being called. I tried both scilinREG and sciREG but no luck(sciREG obviously won't work because it's not being used...).

    After all I was already calling sciReceive before typing character to terminal.

    Well at least I got EMAC working, so even if in the worst case SCI doesn't work at all, I would have a way to debug the program if I manage to implement telnet...

  • I used oscilloscope to measure at R123(USB_LINRX) and R125(LIN_RX) and it turned out that CPU wasn't getting signal at all. I don't know exactly which point is problem but it seems that hardware is broken somehow.

    So, the problem is not resolved, but... well, it's resolved. I will find another way to debug the board.

    Still thanks for helping me out, I learnt very much from this thread.