How can I receive a message by UART with Serial_LDD??

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can I receive a message by UART with Serial_LDD??

1,839 Views
arturoarteaga
Contributor II

Hi,

 

I have just managed to send a message to PC from a MK20DX256VLH7 microcontroller after changing the proposed configuration in “Getting started Guide for Processor Expert”.

 

Now I want to receive data from PC to microcontroller and to re-send from microcontroller to PC the same data. I have developed a new Project for testing to inizialite a future new application. The problem is that my project doesn´t receive anything now.

 

I have attached my proyect in this mail (Serie_Comunication) in which I use “AS1_OnBlockReceived” function in "Events.c" file. I think “AS1_OnBlockReceived” function should be called in "Events.c" file when a data is received but this function isn´t called when I send data from PC to microcontroller by writing from a keyboard in Tera application in order to send data to microcontroller. In this “AS1_OnBlockReceived” function I use “SendBlock” function (it´s just functional) and also I use “GPIO1_ToggleFieldBits” (this function makes a toggle in a led) in order to check if the function is really called “AS1_OnBlockReceived” function.

 

Why “AS1_OnBlockReceived”  function isn´t called when a data is sent for me from the PC to microcontroller?? This function is enabled in AS1 component and also it appears as enabled in “AS1.h” file from the project. Also you can see “PE_ISR(AS1_Interrupt)” function in “AS1.c” file. In “Vectors.c” file, you can see that both of the interrupts also appears.

 

Please, see all captured images attach here related on I have just mentioned before.

 

179898_179898.pngInterrupts_Enabled.png

 

179899_179899.pngFunctions enabled.png

 

179903_179903.pngVectors.png

Should I configure anything more in the AS1 component ?? I can just send, but perhaps should be there any lack to manage the reception data and send data at the same time??

 

I have seen in “AS1.h” file that “TX interrupt” is enabled. In 146 line from “AS1.h” file, you can see the next:

 

#define ENABLED_TX_INT        0x01U    /*!< TX interrupt enabled      */

#define BREAK_DETECTED        0x02U    /*!< Break detected            */

#define TX_COMPLETED          0x04U    /*!< Transmission completed    */

#define ENABLE_TX_COMPLETE    0x10U    /*!< Enable/Disable of TX complete detection. Used in the polling mode only */

 

but I haven’t found anything about RX interrupt enabled. Do you know anyway in the configuration that you can set "RX interrupt" enabled like “TX interrupt”?

 

Do you know if I have to set the RX in another lines??, like the next lines in “AS1.c" that appear like this:

 

LDD_TError AS1_SendBlock(LDD_TDeviceData *DeviceDataPtr, LDD_TData *BufferPtr, uint16_t Size)

{

  AS1_TDeviceDataPtr DeviceDataPrv = (AS1_TDeviceDataPtr)DeviceDataPtr;

 

  if (Size == 0U) {                    /* Is the parameter Size within an expected range? */

    return ERR_PARAM_SIZE;             /* If no then error */

  }

  if (DeviceDataPrv->OutDataNumReq != 0x00U) { /* Is the previous transmit operation pending? */

    return ERR_BUSY;                   /* If yes then error */

  }

  /* {Default RTOS Adapter} Critical section begin, general PE function is used */

  EnterCritical();

  DeviceDataPrv->OutDataPtr = (uint8_t*)BufferPtr; /* Set a pointer to the output data. */

  DeviceDataPrv->OutDataNumReq = Size; /* Set the counter of characters to be sent. */

  DeviceDataPrv->OutSentDataNum = 0x00U; /* Clear the counter of sent characters. */

  DeviceDataPrv->SerFlag |= ENABLED_TX_INT; /* Set the flag ENABLED_TX_INT */

  UART_PDD_EnableInterrupt(UART1_BASE_PTR, UART_PDD_INTERRUPT_TRANSMITTER); /* Enable TX interrupt */

  /* {Default RTOS Adapter} Critical section end, general PE function is used */

  ExitCritical();

  return ERR_OK;                       /* OK */

}

 

 

Or,

 

static void InterruptTx(AS1_TDeviceDataPtr DeviceDataPrv)

{

 

  if (DeviceDataPrv->OutSentDataNum < DeviceDataPrv->OutDataNumReq) { /* Is number of sent characters less than the number of requested incoming characters? */

    UART_PDD_PutChar8(UART1_BASE_PTR, *(DeviceDataPrv->OutDataPtr++)); /* Put a 8-bit character to the transmit register */

    DeviceDataPrv->OutSentDataNum++;   /* Increment the counter of sent characters. */

    if (DeviceDataPrv->OutSentDataNum == DeviceDataPrv->OutDataNumReq) {

      DeviceDataPrv->OutDataNumReq = 0x00U; /* Clear the counter of characters to be send by SendBlock() */

      AS1_OnBlockSent(DeviceDataPrv->UserDataPtr);

    }

  } else {

    UART_PDD_DisableInterrupt(UART1_BASE_PTR, UART_PDD_INTERRUPT_TRANSMITTER); /* Disable TX interrupt */

    DeviceDataPrv->SerFlag &= (uint16_t)(~(uint16_t)ENABLED_TX_INT); /* Clear the flag ENABLED_TX_INT */

  }

}

 

Or

 

PE_ISR(AS1_Interrupt)

{

  /* {Default RTOS Adapter} ISR parameter is passed through the global variable */

  AS1_TDeviceDataPtr DeviceDataPrv = INT_UART1_RX_TX__DEFAULT_RTOS_ISRPARAM;

  register uint32_t StatReg = UART_PDD_ReadInterruptStatusReg(UART1_BASE_PTR); /* Read status register */

 

  if (StatReg & (UART_S1_NF_MASK | UART_S1_OR_MASK | UART_S1_FE_MASK | UART_S1_PF_MASK)) { /* Is any error flag set? */

    (void)UART_PDD_GetChar8(UART1_BASE_PTR); /* Dummy read 8-bit character from receiver */

    StatReg &= (uint32_t)(~(uint32_t)UART_S1_RDRF_MASK); /* Clear the receive data flag to discard the errorneous data */

  }

  if (StatReg & UART_S1_RDRF_MASK) {   /* Is the receiver's interrupt flag set? */

    InterruptRx(DeviceDataPrv);        /* If yes, then invoke the internal service routine. This routine is inlined. */

  }

  if (DeviceDataPrv->SerFlag & ENABLED_TX_INT) { /* Is the transmitter interrupt enabled? */

    if (StatReg & UART_S1_TDRE_MASK) { /* Is the transmitter empty? */

      InterruptTx(DeviceDataPrv);      /* If yes, then invoke the internal service routine. This routine is inlined. */

    }

  }

}

 

Do you know if I should change this code by hand or by “Generate Processor Expert Code” tool?? I think I should write “RX interrupt” by “Generate Processor Expert Code” tool? But In which side of Component Inspector should I change the configurations?

 

Perhaps should I use another component to reseive instead of Serial_LDD?? or another different component to receive as to send?? or perhaps another function or another event function that is called when a data is in the buffer input waiting for receive?

Sorry because of asking a lot of questions, but I am unaware because of the lack of information. I have seen "KINETIS_72MHz_SRC" board sample code, but the only projects are for "code warrior". Are they for "Kinetis Design Studio" too?? and for UART what I've found only two driver files that thay aren´t developed for "Processor Expert" and aren´t developed for "Kinetis Design Studio". Do you know another examples?

 

Thank you again for your effort,

 

Have a nice day,

 

Arturo Arteaga

Original Attachment has been moved to: Serie_Comunication.rar

Tags (1)
0 Kudos
1 Reply

774 Views
arturoarteaga
Contributor II

Hi again,

I´ve been researching in Processor Expert and I've found another component called "Asynchro Serial" component. In this component I´ve seen another methods in order to receive not only with blocks, also it exists funtions that transmit chars. You can see the component in this image.

Reception_3.png

But I´ve found another problem with this component, I can´t initialize the component because the "Auto initialization" setting is disabled, and it appears written "NO" by default in this setting. I'be been looking how to enable this "Auto initialization" setting, but I haven't found anything. Without initializing doesn't recognize "Asynchro Serial" component, and when I build the Project, I have errors of compilation. You can see the components and errors of compilation because of not setting "Auto Initialization". It appears "disabled".

Reception_1.png

For the another component "Serial_LDD" in "AS1.h" file, appears that "AS1_DeviceData" is used only when the auto initialization is enabled. You can see in this file where "AS1_DeviceData" is created. I doesn' t appear anything about "AS1_DeviceData"  component.

Reception_2.png

How can I get "Auto Initialization" enable for "AS2_DeviceData" component? Do you know? I´ve looking at Preferences how can enable this setting, but I haven't found anything?

I know that you are doing a good effort with us to solve doubts, but I would be very grateful if it's possible that I have a quick answer about this issue because we have a delay time in this Project due to our unknowledge of the tolos.

Regards,

Arturo Arteaga