UART_DRV_SendData(0,

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

UART_DRV_SendData(0,

Jump to solution
2,253 Views
randenewberry
Contributor IV

I am using KSDK 1.3.0, Processor Expert, custom PCB with MK02FN64VLH10 controller.

I've been trying to get the com port working for 2 days now...I need some guidance..

Used PE to set up the uart and the program crashes when executing this:

UART_DRV_SendData(0,&data,1u);

After a day and a half, I deleted all the PE stuff, and copied the example from the drivers examples\uart\uart_non_blocking/main.c

Set some definitions / variables, and compiles fine, but it crashes at the same code, UART_DRV_SendData...

Here is the code I copied from the example, the line it crashes on (step over and never returns)  ends with ##########

 

int Uart_Setup(void) // this was main..

{

    uint8_t rxChar, txChar;

    uint32_t byteCountBuff = 0;

 

    // Initialize variable uartState of type uart_state_t

    uart_state_t uartState;

 

    // Fill in uart config data

   const uart_user_config_t uartConfig = {

        .bitCountPerChar = kUart8BitsPerChar,

        .parityMode      = kUartParityDisabled,

        .stopBitCount    = kUartOneStopBit,

        .baudRate        = 38400

    };

 

    // Enable clock for PORTs, setup board clock source, config pin

    hardware_init();

 

    // Initialize the uart module with base address and config structure

    UART_DRV_Init(BOARD_DEBUG_UART_INSTANCE, &uartState, &uartConfig);

 

    // Inform to start non blocking example

    byteCountBuff = sizeof(buffStart);

    UART_DRV_SendData(BOARD_DEBUG_UART_INSTANCE, buffStart, byteCountBuff); // crashes here #########

 

    // Wait until transmission is finished

    while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(BOARD_DEBUG_UART_INSTANCE, NULL)){}

 

    // Inform user of what to do

    byteCountBuff = sizeof(bufferData1);

    UART_DRV_SendData(BOARD_DEBUG_UART_INSTANCE, bufferData1, byteCountBuff);

 

    // Wait until transmission is finished

    while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(BOARD_DEBUG_UART_INSTANCE, NULL)){}

 

    while(true)

    {

        // Call received API

        UART_DRV_ReceiveData(BOARD_DEBUG_UART_INSTANCE, &rxChar, 1u);

 

        // Wait until we receive a character

        while (kStatus_UART_RxBusy == UART_DRV_GetReceiveStatus(BOARD_DEBUG_UART_INSTANCE, NULL)){}

 

        // Echo received character

        txChar = rxChar;

        UART_DRV_SendData(BOARD_DEBUG_UART_INSTANCE, &txChar, 1u);

    }

 

}

 

FYI.

Crashes in startup_MK02F12910.s at the below line when I pause

 

b    DefaultISR   // ################ always is here when I pause
.size DefaultISR, . - DefaultISR

 

/*Macro to define default handlers. Default handler 
*will be weak symbol and just dead loops. They can be
*overwritten by other handlers */
.macro def_irq_handler    handler_name
.weak \handler_name
.set  \handler_name, DefaultISR
.endm
Labels (1)
1 Solution
1,482 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Rande,

Please be sure enable the UART clock .

And please run into the function UART_DRV_SendData() to check when run to which code , it crash.

And you can also try this function : UART_DRV_SendDataBlocking().

After these , if it still can not  work , please send your project to me !

Hope it helps

Alice

View solution in original post

0 Kudos
Reply
6 Replies
1,483 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Rande,

Please be sure enable the UART clock .

And please run into the function UART_DRV_SendData() to check when run to which code , it crash.

And you can also try this function : UART_DRV_SendDataBlocking().

After these , if it still can not  work , please send your project to me !

Hope it helps

Alice

0 Kudos
Reply
1,482 Views
randenewberry
Contributor IV

Hi Alice,

If I need to post this on NXP site I will..let me know..but if not, here

is the issue:

The UART is sending bytes, but it repeatedly sends when not called..

Here is the "send a byte" routine and some pics of the tera term output..

CODE: I made a loop and toggled an LED each time I called the UART TX.

PROBLEM is the UART continually sends, I only want to send one byte, can

you see what is wrong?

Here is the code:

void SendSerialChar(byte data)

{

uint32_t i; //for tests

byte DataToSend=0x30; // for test

// below loop is used for testing

{

while(1)

{

if(DataToSend>0x39)

{

DataToSend=0x30;

}else

{

DataToSend++;

}

TP6_TGL; // this is a test LED

UART_DRV_SendData(0, &DataToSend, 1u);

__ASM("nop"); //nop is here for a breakpoint..prog gets here

about once a second.. .

for(i=0;i<10000000;i++) // delay is about a second or so per 10

million..

{

__ASM(" nop");

}

}

}

}

This is the PIC of tera Term recording the data:.. Each time the LED

toggles the number being sent changes..

Thank you,

Rande Newberry

H-ITT, LLC, a Hyper-Interactive Teaching Technology Company

420 Shearer Blvd.-Cocoa, FL, 32922

PH: 888-322-0089

rande@h-itt.com

0 Kudos
Reply
1,482 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Rande,

I think you enable the TX callback, if yes, there is a bug on the KSDK UART driver,

you need to fix it , and then re-build the KSDK lib , then build your project .

The fix method is

Add these code into the function of "void UART_DRV_IRQHandler(uint32_t instance)" in the file of "fsl_uart_driver.c"

++uartState->txBuff;

--uartState->txSize;

after add , it will like this :

pastedImage_2.png

also if you use receive function , also fix it :

pastedImage_3.png

Hope it can helps you

Alice

1,482 Views
randenewberry
Contributor IV

Hi Alice,

I disabled callback in PE and everything is OK!

Please know that I am just beginner, and using the default is my first

choice, you helped me a lot!

Thank you very much.

Rande Newberry

H-ITT, LLC, a Hyper-Interactive Teaching Technology Company

420 Shearer Blvd.-Cocoa, FL, 32922

PH: 888-322-0089

rande@h-itt.com

0 Kudos
Reply
1,482 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Rande,

OK, welcome !

BR

Alice

0 Kudos
Reply
1,482 Views
randenewberry
Contributor IV

Hi Alice,

The problem is caused by something else in the project.

I created a new project last night and with PE I created the UART

exactly like I did in the main project and it works fine.

So, I'll back out some functions until I isolate the cause.

Thank you

Rande Newberry

H-ITT, LLC, a Hyper-Interactive Teaching Technology Company

420 Shearer Blvd.-Cocoa, FL, 32922

PH: 888-322-0089

rande@h-itt.com

0 Kudos
Reply