Infrared control of TI CC2541

Source: Internet
Author: User

For a whole week, the whole ... About 40 hours, least.

Here is the result, which can only be delayed by one delay.:

unsigned char time;
unsigned char irvalue[6];
#pragma vector = P0int_vector
__interrupt void P0_isr (void) {
unsigned char j,k;
unsigned int err;
if (P0IFG & 2) {//If the interrupt identifier is indeed p0_1
time=0;
Ifr_delay_ms (1); ET 1ms
if (irin==0)//If it is still low, exclude
{
P0_3low (); Pull Low P0_3

err=1000; Make an error counter to prevent the program from sticking to the dead
while ((irin==0) && (err>0))//wait for p0_1 to return to high level, according to the characteristics of infrared, theoretically to wait 9ms
{
IFR_DELAY_100US (1); Wait 100us, theoretically, err will only--about 90 times.
err--;
}

if (irin==1)//back to High level
{
P0_3high (); Pull High P0_3
err=500; It's a bit stuck. Redefining Error counters
while ((irin==1) && (err>0))//wait for the falling edge of p0_1.
{
IFR_DELAY_100US (1); Once equal 100US
err--;
}
P0_3low ();
for (k=0;k<4;k++)//Get 4 bytes altogether
{
for (j=0;j<8;j++)//8 bit per byte
{
err=60; Err Recovery count
while ((irin==0) && (err>0))//wait for the low level of the P1_0 past
{
P0_3low ();
IFR_DELAY_100US (1); such as 100US, theoretically, this length is 560us, about 5-6 cycles
err--;
}

err=500; Err recovery
while ((irin==1) && (err>0))
{
P0_3high ();
IFR_DELAY_100US (1); such as 100US, there are two cases, one is bit 1, the high-level length is 1120us, 11 cycles, if it is bit 0, is 560us, 5-6 cycles.
time++;
err--;
if (time>30)//If you wait too long, just forget it and make a mistake.
{
Ea=1;
Return
}
}

irvalue[k]>>=1; Make a bit move, because the infrared is transmitted from the low start.
if (time>=8)
{
irvalue[k]|=0x80; More than 8 cycles, basically determined to be 1
}
time=0;
}
}
}

if (irvalue[2]!=~irvalue[3])//Here is a verification of the infrared protocol, that is, the data code is complementary, if not complementary, proved to be wrong.
{
Return
}
}
Key_nop ();

P0IFG &= ~ (1 << 1);
p0if = 0;
EA = 1;
}else{
P0IFG = 0;
p0if = 0;
}
}

and modify the Bluetooth connection configuration:

Minimum Connection interval (units of 1.25ms, 80=100ms) if automatic parameter update request is enabled
#define DEFAULT_DESIRED_MIN_CONN_INTERVAL 240

Maximum Connection interval (units of 1.25ms, 800=1000ms) if automatic parameter update request is enabled
#define DEFAULT_DESIRED_MAX_CONN_INTERVAL 320

Slave latency to use if automatic parameter update request is enabled
#define Default_desired_slave_latency 4

Supervision Timeout value (units of 10ms, 1000=10s) if automatic parameter update request is enabled
#define DEFAULT_DESIRED_CONN_TIMEOUT 600

Whether to enable automatic parameter update request If a connection is formed
#define Default_enable_update_request TRUE

Connection Pause Peripheral time value (in seconds)
#define Default_conn_pause_peripheral 6

Inside the simpleperipheral.c file.

Let's say why delay, because delay is the most foolish thing to look at.

Start from the beginning:

Here is an example of infrared data packet:

The actual catch is this:

Well, it's the reverse, because the launch and reception are reversed.

That's not the point.

Here's the point.

OK, my first thought was that, starting a timer, the timer would count every 10 or 100 us, and then each rising or falling edge would know how long it had been in the middle compared to this count of the previous Mark Point.

As a result, I found that the final data is always wrong, originally sent is 4 byte is 0x00,0xff, 0x0c,0xf3, but the probability of error up to 20%, many times is XX, E0, 0E what.

Later I will counter timer made to output high and low level, so that I can observe, really found that the counter each about dozens of MS, there will be a gap, (forget), to prove that the timer in this gap was interrupted, interrupted even the timer interrupted did not go in.

I'm going to break the priority for various changes next.

To know, 2541 interrupt priority, only 4 levels, 0,1,2,3 to two-tier system is 00, 01, 10, 11, in short, the RF interrupt is definitely the highest priority, broadcast it, probably.

In summary, modifying the interrupt priority does not resolve any issues.

Finally, it is delay ... But set the

#define Default_desired_slave_latency 4

Do you believe that disconnecting is a better situation?

Test in ...

Infrared control of TI CC2541

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.