Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 4 Forum Discussions

Anonymous
Not applicable

Hi

I want interrupt driven data transmission.

My tx_buff size is 8 bytes. its is working  fine unless i have tx less than 8 bytes,.

But above that data is not transmitted.

pls help me

regards

santosh

   this is my init code

    UART_InterComm_SetCustomInterruptHandler(&Uart_InterComm_RxIntHandler);//start Rx and Tx interrupt   

    UART_InterComm_Start();   

    UART_InterComm_ClearRxInterruptSource(UART_InterComm_INTR_RX_NOT_EMPTY);

    UART_InterComm_ClearTxInterruptSource(UART_InterComm_INTR_TX_NOT_FULL); //5.12.2018 clear Tx_EMPTY interrupt 

    UART_InterComm_SetTxInterrupt(0- UART_InterComm_INTR_TX_NOT_FULL);

isr

void Uart_InterComm_RxIntHandler(void)

{

    if ((UART_InterComm_GetRxInterruptSourceMasked() & UART_InterComm_INTR_RX_NOT_EMPTY) != 0)

    {

        InterCommSerialStruct.InterCommRxBuffer[InterCommSerialStruct.InterCommRxWritePtr] = (unsigned char)UART_InterComm_UartGetByte();

        InterCommSerialStruct.InterCommRxWritePtr++;

        if(InterCommSerialStruct.InterCommRxWritePtr > INTERCOMMBUFFERSIZE)

            InterCommSerialStruct.InterCommRxWritePtr =0;      

        InterCommSerialStruct.InterCommRxDiffPtr++;       

        UART_InterComm_ClearRxInterruptSource(UART_InterComm_INTR_RX_NOT_EMPTY);

    }

   

    if ( (UART_InterComm_GetTxInterruptSourceMasked() & UART_InterComm_INTR_TX_NOT_FULL) != 0 ) // RX interrupt 

    { 

        if(InterCommSerialStruct.InterCommTxDiffPtr > 0)

        {

            UART_InterComm_UartPutChar(InterCommSerialStruct.InterCommTxBuffer[InterCommSerialStruct.InterCommTxReadPtr]);

            InterCommSerialStruct.InterCommTxReadPtr++;

            if(InterCommSerialStruct.InterCommTxReadPtr >= INTERCOMMBUFFERSIZE )

            {

                InterCommSerialStruct.InterCommTxReadPtr = 0;

            }

            InterCommSerialStruct.InterCommTxDiffPtr--;

            if(InterCommSerialStruct.InterCommTxDiffPtr == 0)

            {

                //serialIntOff;                      // Disable transmitter interrupt 

                UART_InterComm_SetTxInterrupt(0- UART_InterComm_INTR_TX_NOT_FULL);

            }   

            UART_InterComm_ClearTxInterruptSource(UART_InterComm_INTR_TX_NOT_FULL); // clear interrupt             

        }

        else

        {

            UART_InterComm_SetTxInterrupt(0-UART_InterComm_INTR_TX_NOT_FULL);

            UART_InterComm_ClearTxInterruptSource(UART_InterComm_INTR_TX_NOT_FULL); // clear interrupt             

        }   

        //if ( tailTX == headTX )                // Check if all data is transmitted 

    } 

   

}

/////////////////////////////////////////   

txBuffer filling function

void SendPrinterUartData(unsigned char * PrinterData,unsigned char Len)

{

    unsigned char i=0;

    while(i<Len)

    {

   

        InterCommSerialStruct.InterCommTxBuffer[InterCommSerialStruct.InterCommTxWritePtr]= PrinterData;

        InterCommSerialStruct.InterCommTxWritePtr++;

        if(InterCommSerialStruct.InterCommTxWritePtr >= INTERCOMMBUFFERSIZE  )

        {

            InterCommSerialStruct.InterCommTxWritePtr = 0;

        }

        InterCommSerialStruct.InterCommTxDiffPtr++;

        i++;

       

    }   

        UART_InterComm_SetTxInterrupt(UART_InterComm_INTR_TX_NOT_FULL);   

}

0 Likes
1 Solution
Anonymous
Not applicable

Thanks motto tanaka for your reply.I understand my problem.I reduced INTERCOMMBUFFERSIZE to 50 because of ram size limitation .I forgot to increase that and trying to send more than 100 bytes at a time.

regards,Santosh pawar

|

|

View solution in original post

0 Likes
8 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Would be easier to help you when you post your complete project or a shortened version that shows the error so that we all can have a look at all of your settings. To do so, use

Creator->File->Create Workspace Bundle (minimal)

and attach the resulting file.

Bob

0 Likes
Anonymous
Not applicable

Hi,

I have attached code and image.

I want software controlled uart transmit interrupt handler.

whenever transmit buffer empty transmit interrupt should be disabled and it should be enabled again only after atleast one byte in transmit buffer.

but in this code transmit interrupt is continuous.

Please help me to resolve this issue.

Regards,

Santosh Pawar

0 Likes

Off the bat I see that under UART Advanced tab, you haven't checked the Interrupt Source for "RX FIFO Not empty" though you a interrupt handler defined for it. Please do that and check if it works until I debug your project further.

Regards,

Dheeraj

0 Likes
Anonymous
Not applicable

I have don't have any issue while receiving data,my problem is with transmission.

Regards,Santosh

0 Likes

Hello Santhosh,

When you call any function after UART_InterComm_Start() it will not execute any other functions like PrinterTest() in your case because the the control is now in the Uart_InterComm_RxIntHandler(void) and the interrupt UART_InterComm_INTR_TX_NOT_FULL is always true and hence you keep generating the interrupt and clearing it in the else loop as the condition InterCommSerialStruct.InterCommTxDiffPtr > 0 is also never true. This keeps occurring in a loop.

Hence, I just added PrinterTest() before calling UART_InterComm_Start() to load the tx buffer. You can see the ASCII equivalent of 0XAA being printed as shown below:

uart_output.PNG

I have attached the cleaned project below for your reference, please change it to your appropriate device using the device selector. Hope this answers your query

Regards,

Dheeraj

0 Likes

Hi,

In your SendPrinterUartData(), you are managing ring buffer read pointer, but you are not checking the overflow of the ring buffer.

So you may need to check if InterCommSerialStruct.InterCommTxDiffPtr is less or equal to INTERCOMMBUFFERSIZE.

But I don't think above issue can be the immediate reason of your current problem,

which is you have problem when sending tx data whose size is greater than 8 bytes.

I would check

If UART_InterComm_UartPutChar() is actually called, when sending tx data larger than 8.

If InterCommSerialStruct.InterCommTxReadPtr is within the range of INTERCOMMBUFFERSIZE.

If the value of the argument of UART_InterComm_UartPutChar() in the Uart_InterComm_RxIntHandler() is valid.

moto

0 Likes

Hi,

I've just downloaded your project and re-targeted the device to CY8C4247AZI-M485

so that I can debug it with my CY8CKIT-044.

To test the project I modified

(1) PrintTest

from > memset(PrinterUartBuff,0xAA,sizeof(PrinterUartBuff));

to < memset(PrinterUartBuff,'a',sizeof(PrinterUartBuff));

so that I can see the data in my terminal emulator (TeraTerm)

(2) main

un-commented the line PrinterTest()

from > // PrinterTest() ;

to < PrinterTest() ;

The result was flood of 'a's, although 100 of 'a's were expected.

000-original.JPG

Then I modified and added

        while (InterCommSerialStruct.InterCommTxDiffPtr >= INTERCOMMBUFFERSIZE)

            ;

after

        InterCommSerialStruct.InterCommTxDiffPtr++;

in  void SendPrinterUartData(unsigned char * PrinterData,unsigned char Len)

so the function is now

=====================

void SendPrinterUartData(unsigned char * PrinterData,unsigned char Len)

{

    unsigned char i=0;

    while(i<Len)

    {

        InterCommSerialStruct.InterCommTxBuffer[InterCommSerialStruct.InterCommTxWritePtr]= PrinterData;

        InterCommSerialStruct.InterCommTxWritePtr++;

        if(InterCommSerialStruct.InterCommTxWritePtr >= INTERCOMMBUFFERSIZE  )

        {

            InterCommSerialStruct.InterCommTxWritePtr = 0;

        }

        InterCommSerialStruct.InterCommTxDiffPtr++;

        while (InterCommSerialStruct.InterCommTxDiffPtr >= INTERCOMMBUFFERSIZE)  // <---- added

            ;                                                                    // <---- added

        i++;

    }   

        UART_InterComm_SetTxInterrupt(UART_InterComm_INTR_TX_NOT_FULL);   

}

=====================

The result was

001-after.JPG

better?

moto

0 Likes
Anonymous
Not applicable

Thanks motto tanaka for your reply.I understand my problem.I reduced INTERCOMMBUFFERSIZE to 50 because of ram size limitation .I forgot to increase that and trying to send more than 100 bytes at a time.

regards,Santosh pawar

|

|

0 Likes