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

cross mob
lock attach
Attachments are accessible only for community members.
Manoj_Kumar
Level 3
Level 3
50 sign-ins 25 replies posted 10 questions asked

I am trying to do a basic UART communication, but there are two different channels (P0_2 & P03) and (P2_0 & P2_1).

I want first function to work with pins P0_2 & P0_3.

And second function to work with P2_0 & P2_1.

I want both the UART functions to be working in a loop. I have attached the code, please refer that. Thank you

0 Likes
21 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

@Manoj_Kumar ,

Which PsoC6 are you planning on using?

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

CY8C6245LQI-S3D42

0 Likes
Giraffe1492
Level 5
Level 5
25 sign-ins 25 likes received 10 solutions authored

Thank you for providing the PSoC 6 device part number (CY8C6245LQI-S3D42). To implement UART communication on two different channels, you can use the SCB (Serial Communication Block) component in PSoC Creator. The SCB component can be configured as UART, I2C, or SPI. In your case, you will need two SCB components configured as UART.


Here's a step-by-step guide to setting up two UART channels:

  1. Open PSoC Creator and create a new project for your PSoC 6 device (CY8C6245LQI-S3D42).
  2. Go to the Components tab and search for \"SCB\". Drag and drop two SCB components onto your schematic.
  3. Double-click on each SCB component to open the configuration window. Set the mode to \"UART\" and configure the UART settings as needed (baud rate, data bits, stop bits, etc.).
  4. Assign the appropriate pins for the TX and RX signals of each UART channel. Make sure to choose pins that are not in conflict with other functions.
  5. Build the project to generate the API functions for the SCB components.
  6. In your main.c file, include the necessary header files for the SCB components and initialize them using the generated API functions. For example:

 #include \"project.h\"
int main(void) { __enable_irq(); /* Enable global interrupts. */
/* Initialize and start UART components */ UART_1_Start(); UART_2_Start();
/* Your code here */ }

Now you can use the generated API functions to send and receive data through both UART channels. For example,https://www.infineon.com/cms/en/product/microcontroller/?redirId=54599#collapse-d60188f4-2a69-11ec-b...
https://www.infineon.com/cms/en/product/microcontroller/?redirId=54599
https://www.infineon.com/cms/en/product/microcontroller/?redirId=143858#collapse-d60188f4-2a69-11ec-...

 

0 Likes

Thank you for the response @Giraffe1492 , But am using the Modustoolbox for programming the board. Can you provide any solution using Modustoolbox?

 

0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

@Manoj_Kumar ,

Thank you for supplying the part number you are planning to use.

Refer to the "Multiple Alternate Functions" chart found in the PSoC6 data sheet and shown below.

Updated:

Len_CONSULTRON_0-1685721528094.png

Len_CONSULTRON_2-1685721631130.png

Len_CONSULTRON_3-1685721735141.png

Len_CONSULTRON_4-1685721806493.png

In summary here is a simplified table as to the SCB # and the UART Rx and Tx pins available.

SCB # Rx pin Tx pin
0 P0.2 P0.3
1 P2.0 or 10.0 P2.1 or P10.1
2 P3.0 or P9.0 P3.1 or P3.1
3 P6.0 P6.1
4 P7.0 or P8.0 P7.1 or P8.1
5 P5.0 or P11.0 P5.1 or P11.1
6 P6.4 or P12.0 or P13.0 P6.5 or P12.1 or P13.1
7 P1.0 P1.1
Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.
Manoj_Kumar
Level 3
Level 3
50 sign-ins 25 replies posted 10 questions asked

I tried with pin P2_0 ,P2_1 and P0_2 and P0_3.

I tried to run them individually but the 2nd function failed. So the P0_2 and P0_3 pins are failing.

Here is the code, Please can you update this code and check and maybe share a working code back. Thank you.

0 Likes

@Manoj_Kumar ,

Can you share the MTB project for this issue?

At least, can you share the BSP configuration file?  I don't have the correct BSP info to run and test this program.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.

Adding BSP.

0 Likes

@Manoj_Kumar ,

I have at least a partial answer.

In your function Initialize() you have the following line:

cyhal_uart_init(&uart_obj2, P0_2, P0_3, NC,NC,NULL, &uart_config2);

If you were monitoring the return value from this function you will notice an error.

Here are the arguments for the function:

cy_rslt_t cyhal_uart_init(cyhal_uart_t *obj, cyhal_gpio_t tx, cyhal_gpio_t rx, cyhal_gpio_t cts, cyhal_gpio_t rts, const cyhal_clock_t *clk, const cyhal_uart_cfg_t *cfg);

The error is because your are using P0_2 as the Tx pin and P0_3 as the Rx pin for this SCB.   This is reversed and may be the reason why P0_2 and P0_3 doesn't work.

Instead use:

cyhal_uart_init(&uart_obj2, P0_3, P0_2, NC,NC,NULL, &uart_config2);

The return value is 0 (=no error).

Len
"Engineering is an Art. The Art of Compromise."
Manoj_Kumar
Level 3
Level 3
50 sign-ins 25 replies posted 10 questions asked

Thank you @Len_CONSULTRON , Both the functions are working properly now, its was a mistake from my end, thank you for correcting it.

 

0 Likes

@Manoj_Kumar ,

Happy to hear you got it working.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
Manoj_Kumar
Level 3
Level 3
50 sign-ins 25 replies posted 10 questions asked

@Len_CONSULTRON , The functions are invoked properly, but when am reading the value, the read buffer is always empty.

The write function is working or not i doubt that.

0 Likes

@Manoj_Kumar ,

You have at least provided the BSP.  That's a start.   I will look at the new issue shortly.

There is information lacking for me to help further.

For starters:

  • What are P2.0 and P2.1 connected to?
  • What are P0.2 and P0.3 connected to?
Len
"Engineering is an Art. The Art of Compromise."
0 Likes
Manoj_Kumar
Level 3
Level 3
50 sign-ins 25 replies posted 10 questions asked

I had connected Tx to Rx and Rx to Tx as loopback, I am just trying to check the pulse on TX pins(P2_1 & P0_3) on oscilloscope. In the code as you can see I am continuously trying to transmit "1234" using  code "

cyhal_uart_write(&uart_obj2, (void*)tx_buf2, &tx_length);
On the Oscilloscope, I am not able to see any tx pulses.
 
0 Likes

@Manoj_Kumar ,

I'll wire it up as you indicated.

Notes:

based in uart1() and uart2() you are constantly sending "1234A".

Also, your main() code has commented out uart1().

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.

@Manoj_Kumar ,

Here is a modified version of your main.c file.

There are generally a couple of issues you are running into.

Issue #1:  You don't check the result value from the hal functions your are calling.

You are assuming you wrote the function arguments correctly.  You are not checking the cy_rslt_t return value.  This is how I notice that your original issue of reversing the Rx and Tx pin assignments were the issue.

I've added a return value ("rst") to your hal function calls.  I recommend debugging your code and step through the functions to make sure the return value is 0 (= no error).

Issue #2: cyhal_uart_read() argument rx_length needs to be non-zero.

In debugging your code, the rx_length argument you are passing is eventually being set to 0.  This i because running cyhal_uart_read() will modify the value of rx_length with the number of bytes received in the FIFO.

If the value of rx_length is 0, the code gets stuck in an CY_ASSERT_L1() which halts the code for running further.

When debugging, it get stuck at the CY_ASSERT_L1() code line below in file cy_scb_uart.h:

__STATIC_INLINE uint32_t Cy_SCB_UART_GetArray(CySCB_Type const *base, void *buffer, uint32_t size)
{
    CY_ASSERT_L1(CY_SCB_IS_BUFFER_VALID(buffer, size));

    return Cy_SCB_ReadArray(base, buffer, size);
}

By setting the rx_length argument to some anticipated value ("1234A" -> 5 characters) is appears to continue to run instead of halting.

To do this, look at my modifications:

void uart2(){
...
	    /* Begin Rx Transfer */
		/* The rx_length must be set since it is potentially reset by the previous cyhal_uart_read() call.
		 * See the rx_length arg in the function call */
		rx_length = 5;
		rst = cyhal_uart_read(&uart_obj2, (void*)rx_buf2, &rx_length);
...
}

void uart1(){
...
	    /* Begin Rx Transfer */
		/* The rx_length must be set since it is potentially reset by the previous cyhal_uart_read() call.
		 * See the rx_length arg in the function call */
		rx_length = 5;
		rst = cyhal_uart_read(&uart_obj1, (void*)rx_buf, &rx_length);
...
}
Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.
Manoj_Kumar
Level 3
Level 3
50 sign-ins 25 replies posted 10 questions asked

I have attached the updated code file, and yes both the functions are constantly sending the value "1234A". Please remove the commented uart1(), that was just for testing if the second function works or not. Please refer the attached file.

0 Likes

@Manoj_Kumar ,

Are you having any further issues now that I helped with the rx_length issue?

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.

Yes @Len_CONSULTRON , I am trying the same transmission using the Async part, as it will be good to have control on when the transmission is done . Here I have written the attached code.

I am using  cyhal_uart_write_async() or cyhal_uart_write().

The uart_interrupt_handler() is not creating any interrupt which is an issue. I have used the variable  isTransmitComplete  to indicate the Transmission complete interrupt generation.

I want isTransmitComplete to be true and it should not get stuck in the while loop. I have attached the code please refer and check if you can resolve it. I have commented the write methods, Please feel free to uncomment them and try them. thank you

0 Likes

@Manoj_Kumar ,

Your latest main.c is missing only one thing that is preventing the UART interrupt handler from being called.

The fix is ...  Enable the interrupts!!!!!!!!!!

Add the following line after the cyhal_uart_enable_event() call.

    __enable_irq();

 Once I enable the interrupts, the handler gets called and isTransmitComplete has valid values.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.
Manoj_Kumar
Level 3
Level 3
50 sign-ins 25 replies posted 10 questions asked

Thank you for that the program with single UART Channel is working now. So i tried to use the dual UART Channels running on two different threads. But instead of running both the thread, only one thread is running which the the first thread, I want both the threads to be running simultaneously. Can you check with that? I have attached the file for reference. 

0 Likes