MK12 UART

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

MK12 UART

跳至解决方案
2,446 次查看
mylim
Contributor IV

Hi, I just started using Kinetis and MCUexpresso.

I am having some issue with my UART - RS485 which I am not sure if i did it correctly.

I transmitted data to the board but it didn't trigger the Interrupt.

 
I have referred to MCUExpresso SDK API Reference Manual.

I am using at 12MHz Crystal with 22pF capacitor.

Core/System/Bus Clock is 48MHz.
I have RS485 communication initialized as follow;

#define UART0_HANDLER UART0_RX_TX_IRQHandler

#define UART0_IRQ_ID UART0_RX_TX_IRQn

#define UART0_ERR_HANDLER UART0_ERR_IRQHandler

#define UART0_ERR_IRQ_ID UART0_ERR_IRQn

void Init_UART0(void)

{

   /* Structure of initialize UART */

   uart_config_t uartConfig;

   uart_stop_bit_count_t uartStopBit;

   UART_GetDefaultConfig(&uartConfig);

   uartConfig.baudRate_Bps = 4800U;

   uartConfig.parityMode = kUART_ParityDisabled;

   //uartConfig.stopBitCount = kUART_OneStopBit;

   uartStopBit = kUART_OneStopBit;

   uartConfig.txFifoWatermark = 0;

   uartConfig.rxFifoWatermark = 1;

   UART_Init(UART0, &uartConfig, 48000000U);    UART_EnableInterrupts(UART0,kUART_RxDataRegFullInterruptEnable);

   EnableIRQ(UART0_IRQ_ID);

  

   printf("\r\nUART0 Initialized ...");

}

void UART0_HANDLER(void)

{

   if(UART0->S1 & UART_S1_RDRF_MASK)

    {

    }

}

Please advise.

Thanks.

1 解答
2,353 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi mylim,

   You mentioned you are using the 12Mhz crystal.

   Do you check your core clock?

   The TWR-K21 is using the external 8Mhz crystal.

   UART0 is using the system clock as the clock source:

pastedImage_1.png

If your core clock is 48Mhz, then you can use :

UART_Init(UART0, &uartConfig, 48000000U);

BTW, do you also configure the correct pinmux UART pins?

I suggest you use the official examples, modify the .s, system_chip.c, .h, and the drivers, then test it on your side at first.

 

Wish it helps you!

If you still have questions about it, please kindly let me know.

Best Regards,

Kerry

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

在原帖中查看解决方案

3 回复数
2,353 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi mylim ,

  I suggest you use our SDK code for your K12, which can be downloaded from this link:

Welcome | MCUXpresso SDK Builder 

  Select your K12 chip:

pastedImage_2.png

Generate the SDK code, the SDK code already has the MCUxpresso IDE.

 After you download it, please refer to the get start document in the SDK/doc

10.jpg

When you open the SDK project, it is for K21, but you can use the related driver, .s file to replace your project related files:

\SDK_2.3.1_MK12DN512xxx5\devices\MK12D5

The code already have the UART interrupt code.

About the 485, you can use the GPIO an the 485 direction pins.

Wish it helps you!

If you still have questions about it, please kindly let me know.

Best Regards,

Kerry

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 项奖励
回复
2,353 次查看
mylim
Contributor IV

Hi kerryzhou,

I have installed the SDK when i created the project and the UART Driver is already in my project folder.

Are there any difference to use the driver from the example?

Another question is by calling UART_Init, which my system clock is 48MHz and baudrate required is 4800
it should be 

UART_Init(UART0, &uartConfig, 48000000U); ?

Please advise.

Thanks.

pastedImage_4.png

pastedImage_5.png

0 项奖励
回复
2,354 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi mylim,

   You mentioned you are using the 12Mhz crystal.

   Do you check your core clock?

   The TWR-K21 is using the external 8Mhz crystal.

   UART0 is using the system clock as the clock source:

pastedImage_1.png

If your core clock is 48Mhz, then you can use :

UART_Init(UART0, &uartConfig, 48000000U);

BTW, do you also configure the correct pinmux UART pins?

I suggest you use the official examples, modify the .s, system_chip.c, .h, and the drivers, then test it on your side at first.

 

Wish it helps you!

If you still have questions about it, please kindly let me know.

Best Regards,

Kerry

 

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

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------