Kendryte K210 communication about CTM2210LB

Our current project has a function of wireless switch, then we use CTM2210LB (receiving) and CTM2150L (sending) modules, and the receiving module is connected to the IO of K210

By default, CTM2210LB and CTM2150L can be paired. If you need to modify others, you need to modify it with a burner. I won’t elaborate on how to modify it here, because I haven’t modified it myself.

Then CTM2210LB is a standard EV1527 protocol, which requires IO to solve

I thought it was complicated before, and I wanted to use a timer and an external interrupt to do it, but after thinking about it carefully and referring to the information of the bloggers, I finally decided to use only the timer to do it.

The principle is actually very simple, that is, set a 50us timer to interrupt, and then query the high and low levels of IO, if it is low, then +1, and then calculate the time

Take my example, the low level time:

bit0: about 500us

bit1: about 200us

Synchronization code: about 6ms

One thing to note here, as long as the variables in the interrupt, you need to add volatile, including modifying registers and the like, you need to add, don’t ask me why, I won’t tell you because I didn’t add this for several days. Behind is still a professional reminder

In fact, this is the case. After adding volatile, your value will be updated in time, because the read value is in the cache, and sometimes if it is not updated in time, it will cause the value you read to be abnormal and problems will occur.

Maybe I'm the better one, so I will record it here to prevent this kind of error in the future. Modify registers, interrupts, and even between threads. It is better to add variables if there are any, just in case.

Not much to say, the code first:

Guess you like

Origin blog.csdn.net/smile_5me/article/details/109390046