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

PSoC™ Creator & Designer Forum Discussions

DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 I am having trouble figuring out how to set up the UART Receive interrupt. I managed to get gthe example TX and RX code and modified for TX and RX ok but I need to do the following and not sure how to set this up and how to access variables in the interrupt.

   

I have 2 applications. The first is as follows:

   

State Machine within RX interrupt as each Byte is received. 

   

The RX pin is continuously toggling. A leading and sequence of bytes marks start of packet so I need to discard unwanted bytes until the lead-in sequence is detected and then gather bytes into a buffer until the correct number of bytes is received.

   

Do I just set the RX buffer to minimum so the program generates interrupt on each RX byte and then put my state machine into UART_RX.C ?

   

The second application is simpler in that it can receive the entire packet bvefore I need to process anything. But this one I want a timer to be reset every time a byte arrives and then 20ms after last byte the timer will expire and I set a flag to indicate DatainBuf. Alternately I can change packet structure if the PSOC has some sort of standard component tha can use XON/XOFF for packet reception.

   

The packet lengty is dynamic.

   

Thanks

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

Interrupt handling is done quite easy in the PSoC world:

   

Drop an isr-component and connect it to the interrupt signal. Ude declarations as

   

CY_ISR_PROTO(MyHandler); // Prototype declaration

   

isr_StartEx(MyHandler);

   

 

   

CY_ISR(MyHandler()

   

{

   

// Clear source of interrupt (Check UART state, read off character)

   

}

   

I prefer not to make changes in the generated files although there are clearly marked places where I might do so. But a switch to a different device might spoil my changes.

   

Your quest for constantly monitoring a signal and reacting on a initial marker is not as easy. You may watch your line with some additional logic (Timer / Counter) and ignore all UART-Rx inputs until initial marker found.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

 Thanks Bob,

   

I was trying to play with code in the created "c" and "h" files and then realised it is easy to set up a isr handler in main.c and simply declare the vector to it and away we go. This technology is real "cool" compared the the bits and bytes and poking around I have been doing with PIC micros. It is great that much of what I want to do is handled by API and I don't have to dig down into registeres.

   

I do have one other question for you. I was looking for a one-wire component for reading DS1820 Temperature sensors and managed to get a copy of a project from Victor which has a component in a catalog (not the main catalog) of his project.

   

How can I get the catalog containing the 1-Wire component into the "Cypress" catalog (his is named "default" and appears as another Tab".  I want to be able to create a new project and use that component.

   

Cheers

   

David

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

Because with every new version of Creator the cataög gets updated I would suggest to do as following:

   

Create a folder that contains all your own or foreign created components.

   

When a project needs one of those, import it.

   

To maintain the folder the component gets inserted in, have a look into your "Component Author guide" that came with the Creator- installation

   

 

   

Bob

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

By the way, there is a saying "Thinking PSoC" which tries to explain that there is a huge difference between designing with PSoCs and other embedded micros (PICs for instance)

   

 

   

Happy coding!

   

Bob

0 Likes
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 Thanks again for the help Bob, I appreciate you taking the time to consider my questions and answer them.

   

I did as you said and managed to import Victor's 1-wire component and realize it will need some "porting" to 5LP as it references <devices.h> (which does not seem to be used by 5LP?) and the syntax for setting and clearing digital pins is different. I played arounbd and found how to edit the component but there are quite a few changes needed.

   

Last night I had a play and started getting simple things like interrupt driven timer and buttons, Leds and LCD etc running ok.

   

I still have a bit of black area when it comes to the UART as you can attach an ISR to it but it also has an RX interrupt feature. I am not sure if I need to attach the isr component each time and write a handler in code for isr or whether I can access the RX interrupt directly. I  attempted putting code in the the rxint.c that was created but kept having issues with scope of variables.

   

Next, I will watch the videos dealing with the catalog and learn how to write my own component.

   

I see that if you try to alter the files created after a compile they will be written over next time you compile (which is an excellent feature as it keeps your components safe and resuable) . 

   

In the meantime (before i have learned how to write my own components), can I simply write a "c" and "h" file and "#include" it to my project in "main.c" and it will be complied ok like a traditional compiler process? 

   

I agree with your comment regarding PSOC thinking. I must stop thinking in terms of traditional microcontroller and registers and think in terms of re-routable resources , API's and resuable components. It is hard to "let go" and trust the creator to implement the underlying processes, but I LOVE it! I don't know why I have not been exposed to this technology previously?

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

The process of creating your own component can turn out to be something time-consuming at the first try. There can be a lot to learn since a PSoC's capabilities do not end at the wiring of some 100 pre-defined components. A PSoC5 contains 24 "Universal Building Blocks" (UDBs) which you can program using a "Hardware Description Language" (HDL). Every UDB contains an "Arethmetic and Logical Unit" (ALU) that can be programmed to perform some operations, two "First-In-First-Out" (FIFOs) and a bunch of logic. I can assure you that it is not done just by learning the abbreviations.

   

When I first got in contact with PSoCs I started learning to use all the components by reading (and understanding, which sometimes is not as easy) the datasheets and by getting them to work.

   

So take your time.

   

 

   

Bob

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

Here is a link to something I wrote www.cypress.com/. This component consists mostly of programming, very few hardware. Needs a bit of update.

   

 

   

Bob

0 Likes