UART FRDM DEV BRD KEAZ128 example

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

UART FRDM DEV BRD KEAZ128 example

2,198 Views
irmantasbudrys
Contributor III

Hello All,

I am using FRDM DEV BRD KEAZ128 and S32.  I am measuring analogue signal and I want to send ADC data via UART. I can't find any examples for UART. Are where any examples for UART?   Are where any other examples for other communications like SPI, I2C?

Best Regards,

IB

0 Kudos
13 Replies

1,484 Views
irmantasbudrys
Contributor III

...I want to use UART1 or UART0 to send data.

0 Kudos

1,484 Views
irmantasbudrys
Contributor III

Hello,

Could you explain in more details how to configure it? Because I have changed UART_Init(UART2,&UART_Config) to UART_Init(UART1,&UART_Config)  also I have tried  UART_Init(UART2,&UART_Config) to UART_Init(UART1,&UART_Config) but it is not working. Checking with scope on pins and its definitely not working.

Best Regards,

Irmantas

0 Kudos

1,484 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Irmantas,

If you want the UART0 work, you need change like below:

in "FRDM_KEA128_ADC_Interrupt.c":

     UART_Init(UART0,&UART_Config);

     u8Ch = UART_GetChar(UART0);

in "printf.c":

     #define COM_PORT  UART0

UART0.png

The UART0 and UART1 have two pairs of Pins, you can select them by using UART0PS of SIM_PINSEL0 and UART1PS of SIM_PINSEL1.

Signal multiplexing and pin assignments.png

UART0PS SIM_PINSEL0.png

Best Regards,

Robin

0 Kudos

1,484 Views
irmantasbudrys
Contributor III

Hello,

I do not understand library. In system_SKEAZ1284.h you can find:

#define SIM_PINSEL_UART0PS_MASK  0x80u

which means that PTA2 and PTA3 should be active, but  for me PTB0 and PTB1 is active (sends and receives data).  Can you explain me what I am doing wrong?

Best Regards,

IB

0 Kudos

1,484 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Irmantas,

In SKEAZ1284.h I can find:

#define SIM_PINSEL_UART0PS_MASK  0x80u

It does not mean that the default value of SIM_PINSEL_UART0PS is equal to 1.

If you want to use PTA2 and PTA3, please set the UART0PS bit in SIM_PINSEL and enable the internal pull up resistance.

SIM_PINSEL_UART0PS_MASK.png

Best Regards,

Robin

1,484 Views
charlesasquith
NXP Employee
NXP Employee

Sorry for the late response. Can you verify that your UART instance is actually getting enabled properly? It doesn't look like the UART_Init function alone enables the UART as I don't see

pUART->C2 |= (UART_C2_TE_MASK | UART_C2_RE_MASK );

anywhere in that function.

0 Kudos

1,484 Views
irmantasbudrys
Contributor III

Hello,

I am using  FRDM_KEAZ128_ADC_Interrupt  example  ( from SDK Software Drivers for KEAZ128 ). I can't run UART1 or UART0 with this code. Should it be simply just changing  UART_Init(UART2,&UART_Config);  function UART2 to UART0/1 ?

Could you explain me how to send data via UART1 or UART0 using SDK Software Drivers for KEAZ128?

Best Regards,

Irmantas

0 Kudos

1,484 Views
charlesasquith
NXP Employee
NXP Employee

Hi Irmantas,

yes, you will need to pass the correct base of the UART instance you plan on using to all of the pertinent API functions that require it. Otherwise you would have initialized and configured UART 2 but are trying to send data with UART0/1.

0 Kudos

1,484 Views
irmantasbudrys
Contributor III

Hello,

Thanks for your comments.

Now I am using FRDM_KEA128_ADC_Interrupt code example. Works fine for me.

This function below is used to send data via UART:

printf("\nPOTENTIOMETER conversion value:%d\n",ADC_ConversionBuff_V);

but it can't send floating value like 2,495 (V). Is where any way to send floating value ( for example 2,495 V)  with this function?

Best Regards,

Irmantas

0 Kudos

1,484 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi

Maybe you can refer the driver test code in  SDK Software Drivers for KEAZ128_KEAZ64 using S32DS (REV 0) , it can be download from NXP Freedom Development Platform for Ultra Reliabl|NXP.

SDK-DRIVER-FRDM-KEA-S32DS.png

Best Regards,

Robin

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

1,484 Views
irmantasbudrys
Contributor III

Hello Charles,

Thank you. I was looking for a better example. I am trying to send ADC value (0 to 5V measurement) via UART.  I am using transmit_string(  ) function, but I can't transmit ADC value, this function transmits only word. Could you explaian me more how to send ADC value or show better example code?

Code I am trying to use:

#include "derivative.h"

#include "ADC.h"

#include "clocks.h"

#include "UART.h"

#include "stdio.h"

#include "stdint.h"

#include "inttypes.h"

#define PTE7  7           /* Port PTE7 output to blue LED */

#define PTH0 24           /* Port PTH0 output to red LED */

#define PTH1 25           /* Port PTH1 output to green LED */

uint32_t adcResultInMv = 0;

int main(void){

  int counter = 0;

// int j;

  init_clks_FEE_40MHz();         /* KEA128 8MHz xtal: core 40 MHz, bus 20MHz */

  GPIOB_PDDR |= 1<<PTE7 | 1<< PTH0 | 1<<PTH1;   /* Output ports to LEDs */

  GPIOB_PIDR &= 1<<PTE7 | 1<< PTH0 | 1<<PTH1;   /* Disable inputs (default) */

  init_UART(); /* Initialize UART2 9600 baud, 1 stop, no parity no IRQ */

  init_ADC();   /* Init. ADC: Single conversion, SW trigger; enable adc chans 10 & 22 */

  transmit_string("Running UART example\n\r"); /* Transmit string, new line, return */

  for(;;) {

  convertAdcChan(10);                 /* Convert Channel AD10 to pot on EVB */

  while(adc_complete()==0){}          /* Wait for conversion complete flag */

  adcResultInMv = read_adc_chx();     /* Get channel's conversion results in mv */

  transmit_string( " adcResultInMv " );

    counter++;

  }

}

Best Regards,

Irmantas

0 Kudos

1,484 Views
charlesasquith
NXP Employee
NXP Employee

So the ADC data is typically 16 bits long. The UART data is 8 bits long. Because of this, you'll need to put the ADC data into a 16 bit variable, transmit the first 8 bits using the UART, shift the data variable by 8 bits, and then transmit the last 8 bits after that. I'll try to whip up some example code for you:

uint16_t ADC_GetData(void);

void UART_SendData(uint16_t data);

uint16_t ADC_GetData(void)

{

     uint16_t data;

     while(!(ADCx->SC1n & ADC_SC1_COCO_MASK)){/* Wait for conversion to finish */}

     data = ADCx->Rn     /* Read data register into variable */

     return data;

}

void UART_SendData(uint16_t data)

{

     uint16_t shiftedData;

     UARTx->D = data;     /* Put data into UART Tx data register */

     while(!(UARTx->S1 & UART_S1_TC_MASK)){/* Wait for transfer to finish */}

     shiftedData = data >> 8;

     UARTx->D = shiftedData;

     while(!(UARTx->S1 & UART_S1_TC_MASK)){/* Wait for transfer to finish */}

}

void main(void)

{

     uint16_t data;

          while(1)

          {

               data = ADC_GetData();

               UART_SendData(data);

          }

}

Hopefully this code is good enough for you to understand what I mean. You also may want to make data an array filled with samples that the ADC gives.

Best regards,

Charles

1,484 Views
charlesasquith
NXP Employee
NXP Employee

Hi Irmantas,

You'll want the FRDM-KEA Quick start package. It has example code and peripheral drivers in it.

You can download it from this link:

NXP Freedom Development Platform for Ultra Reliabl|NXP

I hope this is what you're looking for,

Charles