You are here

How to Receive 6 Bytes from UART | Cypress Semiconductor

How to Receive 6 Bytes from UART

Summary: 13 Replies, Latest post by Rahlff on 29 Nov 2013 10:51 AM PST
Verified Answers: 0
Last post
Log in to post new comments.
Rahlff's picture
User
3 posts

Hey.

I am currently working on a project from school.

I am using the PsoC Starter Kit 3.

I am trying to receive 6 byte from UART. I have not been able to do this and have now tryed alot in the last 20 hours.

I have another PSoC which is sending the following every sec.

Byte1 | byte2 | byte3 | byte4 | byte5 | byte6

0xAB  | 0x11  | 0x22  | 0x12  | 0x01  | 0xCD

byte 2, 3, 4, 5 can contain values from 0x00 to 0xFF

I have attached a picture from my Logic Analyser showing the data: 

I have several times made sure that the UART settings are the same on the receiver and sender.

Baudrate 9600 - 8 bit - no polarity - 1 stopbit - no flowcontrol - RS484 enable

I have tryed different approach with different API calls without luck. Sometimes I get some of my data in an array, but mixed up. Thats the closed I have been on a solution.

I have no Warnings on my clocks on the UART.

Anybody having done something similar and been succesfull? Running Creator 3.

Thanks in advance.

 

My last attempt:

 /* ========================================

 *

 * Copyright YOUR COMPANY, THE YEAR

 * All Rights Reserved

 * UNPUBLISHED, LICENSED SOFTWARE.

 *

 * CONFIDENTIAL AND PROPRIETARY INFORMATION

 * WHICH IS THE PROPERTY OF your company.

 *

 * ========================================

*/

#include <project.h>

 

#define FALSE 0

#define TRUE !FALSE

#define MSG_LENGHT 6

 

uint8 dataArray[MSG_LENGHT];

uint8 MessageReady = FALSE;

 

CY_ISR(UART_RX_ISR_FUNC)

{

UART_ReadRxStatus();

if(UART_GetRxBufferSize()>= MSG_LENGHT) 

{

MessageReady = TRUE;

}

}

 

 

int main()

{

int i = 0;

CyGlobalIntDisable;

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

UART_Start();

//Rx_Int_Start(Rx_ISR);

UART_RX_ISR_StartEx(UART_RX_ISR_FUNC);

    CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */

 

    for(;;)

    {

        /* Place your application code here. */

if(MessageReady)

{

for(i = 0; i < MSG_LENGHT; i++)

{

dataArray[i] = (uint8)(UART_GetByte() 0x00FF);

}

MessageReady = FALSE;

    }

}

}

/* [] END OF FILE */

 

 

Rahlff's picture
User
3 posts

 One typo in the code.

(UART_GetByte() 0x00FF) is suppose to be (UART_GetByte() & 0x00FF);

user_119377051's picture
User
866 posts

Hi Rahlff

I would do it like this ...

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

int i; // array index

unsigned char buf[nn]; // buffer area

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

CY_ISR(UART_RX_ISR_FUNC)

{

if( NOT PARITY ERROR something )

{ // read directly and immediately

.. if( i
}

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

void main(void)

{ i= 0;

while(1)

{ if( i>0 ) // receive data existed?

.. { strncat( buf, dataArray, i ); // stack into buf from array

.. if( buf IS COMPLETE ? ) // It's depend on your requirement

.. { // do something by using buf

.. }

.. i= 0; // clear array index

} } // end of while loop

} // end of main

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

user_119377051's picture
User
866 posts

I gotta sleep

Thanks

user_119377051's picture
User
866 posts

Oh sorry, important part were missing

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

CY_ISR(UART_RX_ISR_FUNC)

{ if(__NOT_PARITY_ERROR,something__)

..{ // read directly and immediately

... if( i
} }

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

(is it ok??)

user_119377051's picture
User
866 posts

///////////////////////////////////////////////////////////// ;;;
CY_ISR(UART_RX_ISR_FUNC) ;;;
{ if( NOT PARITY ERROR something ) ;;;
{ // read directly and immediately ;;;
.. if( i

user_119377051's picture
User
866 posts

wow noway

user_119377051's picture
User
866 posts

Untitled Page

p.MsoNormal
{margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"MS Pゴシック";
margin-left: 0cm;
margin-right: 0cm;
margin-top: 0cm;
}

Try and try and try


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

int i; 
              
// array index

unsigned char buf[nn];
// buffer area


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

CY_ISR(UART_RX_ISR_FUNC)

{ if( NOT PARITY ERROR something )

  {
// read directly and immediately

    if(
i<MAX_ARRAY ) dataArray[i] = UART_GetByte();

} }


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

void main(void)

{ i= 0;

  while(1)

  { if( i>0 )
// receive data existed?

    { strncat( buf,
dataArray, i );  

// stack into buf from array

      if( buf IS
COMPLETE ? )        
// It's depend on your requirement

      {
// do something by using buf

      }

      i= 0;

  //
clear array index

  } }
// end of while loop

}
// end of main


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

Yes I can sleep

 

user_119377051's picture
User
866 posts

... if( i

user_119377051's picture
User
866 posts

Untitled Page

p.MsoNormal
{margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"MS Pゴシック";
margin-left: 0cm;
margin-right: 0cm;
margin-top: 0cm;
}


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

CY_ISR(UART_RX_ISR_FUNC)

{ if( NOT PARITY ERROR something )

  {
// read directly and immediately

    if(
i<MAX_ARRAY ) dataArray[i
++] = UART_GetByte();

} }


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

user_1377889's picture
User
10803 posts

@PSoC73

Need to increase your number-of-posts ranking?

 

Bob

Log in to post new comments.