4, CC2541 Chip Intermediate tutorial-osal operating system (simple at instruction implementation +IIC software and hardware implementation drive MPU6050)

Source: Internet
Author: User

This article is based on a week CC2541 notes summary

Suitable for overview and quick index of knowledge--

All Links:

Intermediate Tutorial-osal Operating system \osal operating system-a preliminary study of experimental osal

"Insert" sourceinsight-Engineering Establishment method

Intermediate Tutorial-osal Operating System (Osal System solution basic routines)

Intermediate Tutorial-osal Operating system (learn more about-oled && normal keys and 5-directional buttons-interrupts!!!) This system drive layer is not the same as the application layer ~

Intermediate Tutorial-osal Operating system (adc-photoresistors)

Osal Operating System-experiment 16 serial port baud rate extension

Osal operating system-experimental at command preliminary

Osal operating System-experimental 20 simulated IIC communication + hardware IIC (Mpu6050)

Osal operating system-experimental PWM output (change duty duty)

Osal Operating System-Lab 24 watchdog Wachdog

Osal operating System-experimental SNV internal flash data Read and write

Osal Operating System-experimental 29 system sleep level study

Osal Operating System-experiment 31 slave broadcast power modification

First, at command Preliminary (17)

at command through the serial port to communicate

The callback function is invoked when the serial port has data, in order to prevent the callback function from being called frequently , using ( delay + data length control , i.e., exceeding a certain time or exceeding a certain length to invoke Npi_readtransport ( Buffer,numbytes); Read certain data)

The No. 224 line of data received by the serial port calls the at command processing function for processing:

1 //At command handling functions2BOOL Simpleble_at_cmd_handle (UINT8 *pbuffer, uint16 length)3 {4BOOL ret =TRUE;5     CharStrtemp[64];6 7     //1. Testing8     if(length = = 4) && str_cmp (pbuffer, "at\r\n", 4))// at9     {Tensprintf (strtemp, "ok\r\n"); OneNpi_writetransport ((Uint8 *) strtemp, Osal_strlen (strtemp)); A     } -     //2. Set the LED1 of the lamp -     Else if(length = = 9) && str_cmp (pbuffer, "at+led", 6)) the     { -         /* - para:0 ~ 1 - at+led0\r\n: Turn off the light + at+led1\r\n: Turn on the light - default:0 +         */ A         Switch(pbuffer[6]) at         { -          Case‘?‘: -sprintf (strtemp, "ok+get:%d\r\n", g_led1); -Npi_writetransport ((Uint8 *) strtemp, Osal_strlen (strtemp)); -              Break; -          Case' 0 ': ing_led1 = 0; -Halledset (Hal_led_1, Hal_led_mode_off);//Close Led1 tosprintf (strtemp, "ok+set0\r\n"); +Npi_writetransport ((Uint8 *) strtemp, Osal_strlen (strtemp)); -              Break; the          Case' 1 ': *g_led1 = 1; $Halledset (Hal_led_1, hal_led_mode_on);//Light led1.Panax Notoginsengsprintf (strtemp, "ok+set1\r\n"); -Npi_writetransport ((Uint8 *) strtemp, Osal_strlen (strtemp)); the              Break; +         default: ARET =FALSE; the              Break; +         } -     } $     Else $     { -sprintf (strtemp, "error\r\n"); -Npi_writetransport ((Uint8 *) strtemp, Osal_strlen (strtemp)); the  -RET =FALSE;Wuyi     } the  -     returnret; Wu}

258 lines, at\r\n is the test command,

Almost all of the AT command modules in the industry are the first at command, which is used to test whether the module is connected properly.

 264~288, we have written an at command for lighting:at+led?\r\n: Switch status of the enquiry lightat+led0\r\n: Turn off the lightat+led1\r\n: Turn on the light Summary : The overall comparison is simple is to send the serial data to the AT command processing function processing, serial data reception using a certain skill second, simulated IIC communication + hardware IIC (Mpu6050) -

Cc2541 has hardware IIC function, but cc2540 does not have hardware IIC function

Description:this file contains code, common to all sensor drivers. In hal_sensor.c TI has achieved cc2541 hardware IIC Drive, we Use on the line.   SIMPLEBLETEST.C, the Access function written to the mpu6050. The above two functions are implemented to Read and write operation of mpu6050 registers。 The above two files, the realization is gpio analog IIC timing And encapsulates a read-write function that simulates IIC. In Iic.h we define the SCL and SDA of P1.5 and P1.6 as IIC: Summary : IIC and MPU6050 are well encapsulated. Protocol stack is a good thing, easy to transplant!!! It's a treasure trove!
Above is simulation Implementation of IICIts Hardware ImplementationEasier to use:

In simplebletest.c directly to the MPU6050 device address to the I²C initialization function , and then directly call read and write function to read and write!

not finished ~ Follow my cc2541 categories

4, CC2541 Chip Intermediate tutorial-osal operating system (simple at instruction implementation +IIC software and hardware implementation drive MPU6050)

Related Article

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.