- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Which PsoC6 are you planning on using?
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
CY8C6245LQI-S3D42
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
- Open PSoC Creator and create a new project for your PSoC 6 device (CY8C6245LQI-S3D42).
- Go to the Components tab and search for \"SCB\". Drag and drop two SCB components onto your schematic.
- 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.).
- 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.
- Build the project to generate the API functions for the SCB components.
- 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-...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for the response @Giraffe1492 , But am using the Modustoolbox for programming the board. Can you provide any solution using Modustoolbox?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
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 |
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you @Len_CONSULTRON , Both the functions are working properly now, its was a mistake from my end, thank you for correcting it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 "
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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().
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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);
...
}
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you having any further issues now that I helped with the rx_length issue?
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.