Jump to content
Forum sending old emails Read more... ×

Search the Community

Showing results for tags 'tiva c'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • News
    • Announcements
    • Suggestions
    • New users say Hi!
  • Spotlight!
    • Sponsor Spotlight
    • Sponsor Giveaways
  • Energia
    • Energia - MSP
    • Energia - TivaC/CC3XXX
    • Energia - C2000
    • Energia Libraries
  • MSP Technical Forums
    • General
    • Compilers and IDEs
    • Development Kits
    • Programmers and Debuggers
    • Code vault
    • Projects
    • Booster Packs
    • Energia
  • Tiva-C, Hercules, CCXXXX ARM Technical Forums
    • General
    • SensorTag
    • Tiva-C, Hercules, CC3XXX Launchpad Booster Packs
    • Code Vault
    • Projects
    • Compilers and IDEs
    • Development Kits and Custom Boards
  • Beagle ARM Cortex A8 Technical Forums
    • General
    • Code Snippets and Scripts
    • Cases, Capes and Plugin Boards
    • Projects
  • General Electronics Forum
    • General Electronics
    • Other Microcontrollers
  • Connect
    • Embedded Systems/Test Equipment Deals
    • Buy, Trade and Sell
    • The 43oh Store
    • Community Projects
    • Fireside Chat
  • C2000 Technical Forums
    • General
    • Development Kits
    • Code Vault
    • Projects
    • BoosterPacks


There are no results to display.

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



Website URL





Found 25 results

  1. Hi I have a Tiva C TM4C123GXL launchpad. I was wondering if the SD Card booster pack, will fit the Tiva C board? I read it had 40 pin support and had solderable jumpers. Thanks Joe
  2. Hi all, I have a PID algorithm written on TIVA C TM4C123G . I want to setup a PIL simulation with Simulink. Simulink will send the error signal to TIVA, the PID will calculate the control signal and send it back to Simulink. How can I link the TIVA C "TM4C123GH6PM" Launchpad with Simulink and send/receive data in PIL setup? any help ?? Thanks
  3. I have a tm4c129 board. I have installed updates form the board manager for the TIVA C so now I can upload the default examples form Energia. 1. Problem arises when I try to add custom libraries. What is the correct method to add a library? 2. I can find only MSP430 folder at location E:\..\energia-1.6.10E18\hardware\energia , I suppose all boards installed should show up in the hardware library. 3. I have included the library which I am trying to compile Error: WARNING: Category '' in library SD is not valid. Setting to 'Uncategorized' Missing 'maintainer' from library in C:\Users\Admin\Documents\Energia\libraries\SD Error compiling for board LaunchPad (Tiva C) w/ tm4c129 (120MHz). sd-logger-source.zip
  4. Hello, I recently ported over an Energia sketch that had working WiFi functionality in order to help with remote logging for a project I'm working on. The WiFi works well, but now the CCS code that was handling the ADC interrupts and measuring data is no longer functioning. If possible, I would like to make minimal changes to the CCS code as it was working exactly as we desired. I feel like there must be a relatively simple fix that I'm missing but I can't seem to figure it out. Can someone please help figure out what's wrong the ADC interrupt in the following code? #include <stdint.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <math.h> #include "inc/hw_types.h" #include "inc/hw_gpio.h" #include "inc/hw_memmap.h" #include "inc/hw_ints.h" #include "sysctl.h" #include "gpio.h" #include "driverlib/gpio.h" #include "driverlib/timer.h" #include "driverlib/interrupt.h" #include "driverlib/debug.h" #include "driverlib/adc.h" #include "inc/tm4c123gh6pm.h" #include <string.h> #include <WiFiClient.h> #ifndef __CC3200R1M1RGC__ // Do not include SPI for CC3200 LaunchPad #include <SPI.h> #endif #include <WiFi.h> // your network name also called SSID char ssid[] = ""; // your network password char password[] = ""; WiFiClient client; IPAddress server(); uint16_t port = ; #define SAMPLING_RATE 80000.0 // #define TARGET_FREQUENCY 10000.0 // #define BLOCK_SIZE 80 #define BUFFER_SIZE 255 //result cannot be declared in interrupt handler uint8_t flag = 0; uint32_t buffer[BUFFER_SIZE]; uint32_t bufferIndex = 0; float goertzel(uint32_t buffer[]) { int k, i; const float floatN = (float)BLOCK_SIZE; float omega; k = (int) (0.5 + ((floatN * TARGET_FREQUENCY ) / SAMPLING_RATE)); omega = (2.0 * 3.14 * k)/floatN; float sine = sin(omega); float cosine = cos(omega); float coeff = 2.0 * cosine; float Q0 = 0; float Q1 = 0; float Q2 = 0; float scaling_factor = BLOCK_SIZE/2.0; for (i = 0; i < BUFFER_SIZE; i++) { Q0 = coeff * Q1 - Q2 + buffer[i]; Q2 = Q1; Q1 = Q0; } float imag, real, result; real = (Q1 - Q2 * cosine) / scaling_factor; imag = (Q2 * sine) / scaling_factor; result = sqrtf(real * real + imag * imag); return result; } void ADC3IntHandler(void) { float result = 0.0; ADCIntClear(ADC0_BASE, 3); if (flag == 0) { //GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_PIN_0); flag = 1; } else { //GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, 0); flag = 0; } if (bufferIndex >= 255) { bufferIndex = 0; ADCSequenceDisable(ADC0_BASE, 3); result = goertzel(buffer); client.println(result); ADCSequenceEnable(ADC0_BASE, 3); } ADCSequenceDataGet(ADC0_BASE, 3, (buffer + bufferIndex)); bufferIndex++; } void setupADC(void) { SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_25MHZ); //Enable ADC0 and timer SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //pin for testing //GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0); TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); TimerClockSourceSet(TIMER0_BASE, TIMER_CLOCK_SYSTEM); //625 - 40 kHz sampling rate TimerLoadSet(TIMER0_BASE, TIMER_B, 625); TimerControlTrigger(TIMER0_BASE, TIMER_B, true); //Disable before configuring ADCSequenceDisable(ADC0_BASE, 3); ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0); ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); //sequencer 3 on PE3 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); //PE3 ADC pin GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); IntRegister(INT_ADC0SS3, ADC3IntHandler); ADCIntRegister(ADC0_BASE, 3, ADC3IntHandler); IntMasterEnable(); IntEnable(INT_ADC0SS3); ADCIntEnable(ADC0_BASE, 3); ADCSequenceEnable(ADC0_BASE, 3); SysCtlDelay(10); TimerEnable(TIMER0_BASE, TIMER_B); //Timer A conflicts with SPI of wifi module ADCIntClear(ADC0_BASE, 3); } void setup() { setupADC(); WiFi.begin(ssid, password); while ( WiFi.status() != WL_CONNECTED) { delay(300); } while (WiFi.localIP() == INADDR_NONE) { delay(300); } uint8_t tries = 0; while (client.connect(server, port) == false) { if (tries++ > 100) { while(1); } delay(100); } delay(1000); } void loop() { //client.println("hello"); } Thank you!
  5. Niral1426459960

    Tiva C UART

    Hello everyone.. I am beginner with Energia. I have Tiva C series launchpad which features TM4C123G series microcontroller. Now this microcontroller has 8 UARTs. I have tested basic serial communication using energia and it works perfectly fine. Now i want to use UART module 3 of this microcontroller which is pin no 13 and 14 (PC6 and PC7). So how can i do this using Energia..?? Thank you.
  6. Medsimo

    TIVA C, PWM mode

    Hello all !! I have a question about my TIVA board: What is the range of frequencies that we can get for the PWM, taking into account the possibilities of "clock division" and the "number of bits"? I ask you if in case we had to measure a resonator with the PWM as a generator (at 50% duty cycle). regards
  7. Medsimo


    hello People !! I have traying to upload this code (see below) in Tiva C LP with CC2530 AIR MODULE. I have this errors, someone gives me some help please. " I have libreries in order and all" Issues: C:\Users\Myriam\Documents\Energia\libraries\SPI\SPI.cpp: In member function 'void SPIClass::begin()': C:\Users\Myriam\Documents\Energia\libraries\SPI\SPI.cpp:207:55: error: invalid conversion from 'long unsigned int*' to 'uint32_t* {aka unsigned int*}' [-fpermissive] while(ROM_SSIDataGetNonBlocking(SSIBASE, &initialData)); ^ C:\Users\Myriam\Documents\Energia\libraries\SPI\SPI.cpp: In member function 'uint8_t SPIClass::transfer(uint8_t)': C:\Users\Myriam\Documents\Energia\libraries\SPI\SPI.cpp:244:35: error: invalid conversion from 'long unsigned int*' to 'uint32_t* {aka unsigned int*}' [-fpermissive] ROM_SSIDataGet(SSIBASE, &rxtxData); ^ code: Tiva_measurment.ino
  8. sherifsorour

    Led & Switch Program Failure - Tiva C

    Hello Guys, Iam starting to learn embedded systems with Tiva C board. I have issue in understanding simple code below this is part of the code input = GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 , input); PIN4 connected to switch and pin connected to led. It shall take the switch value and show it on the led but it doesn't work. Someone suggested to write the same code with the below if condition and it worked but I don't understand why the above code doesn't work. if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4 ) == GPIO_PIN_4) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 , GPIO_PIN_1 ); } else { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 , 0 ); } Appreciate if you can clarify this to me. Thanks
  9. Hi!, I'm try to connect tm4c123gxl with esp8266: esp8266 tm4c GND GND VCC +3.3V CH_PD +3.3V Rx PD7 (Tx 2) Tx PD6 (Rx 2) I tested with "AT" command, if it's success, it will return "OK". Here is my code: void setup() { Serial2.begin(115200); Serial.begin(9600); Serial2.write("AT"); } //------------------------------------------------------------ void loop() { while (Serial2.available()){ char result = Serial2.read(); Serial.print("Serial2 result:\t"); Serial.print(result); Serial.println(""); } } But It just print 2 lines and nothing else Serial2 result: A Serial2 result: T
  10. Hello ! I'm a student, I wonder if tm4c123gxl can write firmware to esp8266, because I see tm4c has Tx and Rx pins, or I have to buy a USB to TTL ? Here is my firmware I want to flash to esp8266 https://github.com/tuanpmt/esp_mqtt Thank you very much
  11. Fmilburn


    I was inspired a while back by the simplicity of the FFT application written by Shane Ormond and featured on the 43oh blog. It was easy to duplicate and I've made a few changes, additions, and such that seemed worth documenting. I didn't have a signal generator other than the 1kHz square wave on my oscilloscope and some clunky code that I wrote for a microcontroller so I ordered an inexpensive AD9850 and hooked it up to a FR6989 LP so I could use the LCD to display frequency. I've been pleased with the AD9850 and it is hard to beat it for the price. The sine wave is more than sufficient for my needs up to 40 MHz - I don't see any deviation from the scope. The code is here. This is a picture of the setup being tested on the oscilloscope and nailing it: I need to make a little boosterpack for this so it is a little handier to use. I made several modifications to Shane's code: Number of samples can be specified Bin readings are matched with corresponding frequency interval Frequency resolution of bins can be set Frequencies of up to 5 kHz or more can be measured I used a MSP-EXP432 for the most part but the code was also tested and works on the TM4C123. You really need an ARM to get this granularity. The code is here. To increase the sample size and allow measurement up to higher frequencies I used Energia's delayMicroseconds instead of millis. The right way to do this would be with timers and I hope to come back and address this at some point. To calibrate the bins to their actual frequencies I used a simple one step approach with a single pass that measures the deviation in the sampling time from expected to actual. Deviations occur due to the lag associated with Energia code and the actual time it takes to sample. Precision depends on the bin size and number of samples as well as inaccuracies in using delayMicroseconds. I posted the serial output into a spreadsheet to get some plots... 1000 Hz Square Wave 1000 Hz Sine Wave 5000 Hz Sine Wave My original goal was to create something that could process sound in the range of human hearing and this pretty much gets there. I need to clear my desk for another project but hopefully I get back to it some day or perhaps someone else will find it interesting and report back This is my list of potential improvements: use timer for sampling times add a microphone improve the graphical display / GUI It would be neat to get this working on an Educational BoosterPack.
  12. I want to resend each character from one UART port to another. Hardware: Lauchpad TivaC EK-TM4C123GXL. First port is the default port that is connected to microUSB on the board. The second port is UART2 (Rx = PD6; Tx = PD7) connected to DB9 through MAX3232:. Power is VBUS - GND. DB9 is now connected to computer through RS232-USB adapter. I communicate with 1st serial port through serial monitor in Energia (ttyACM0). I communicate with 2nd serial port through serial terminal in Linux (ttyUSB0). Code is very simple: void setup() { // initialize ports: Serial.begin(9600); //connected with USB delay(100); Serial2.begin(9600); //RS232: Rx = PD6; Tx = PD7 delay(100); } void loop() { } void serialEvent() { while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); //send it to RS232 Serial2.print(inChar); } while (Serial2.available()) { // get the new byte: char inChar = (char)Serial2.read(); //send it to UI Serial.print(inChar); } } I got the following: Then I send something from Energia serial monitor (serial) - this message is displayed in linux serial terminal (serial2) - this is all good. Another way (from Serial2 to Serial) it does not work - I send messages from linux terminal, but nothing changes in Energia serial monitor. What is wrong with my setup?
  13. terjeio

    Multimedia Center

    My (crazy) project is getting closer to completion so time to start a project topic. I have verified my Tiva C based controller design and are now waiting for PCBs - will arrive from China in a few days. My background is from Radio/TV servicing and medical electronics, but for the last 25 years I have mainly been working on a large database application written in OpenEdge. Two years ago my preamp that I made some 30 years ago started to fail due to the rubber based switches rotting (a bit like my brain these days...). Since I did not want to buy one I decided to make a new - again with no mechanical parts in the audio path. A lot has happened since back when I was involved in electronics, and I have spent some time doing research for what components are now available - to many one may argue. I decided to use a CPLD programmed in VHDL for the switching logic, high quality analog switches (my original design employed 40 series CMOS for these) and a VCA (voltage controlled amplifier) for volume control. I did not want to introduce a MCU because I believed I would get into trouble with the clock signal interfering with the audio... Anyway, my new design was successful and has now been in service for nearly two years. After doing this I took an interest in learning about microprocessors again, I started out with Atmel/Ardouino and Energia but I found that combination a bit lacking - no easy way to do debugging was a showstopper for me. I found the TI processors more appealing, CCS allows me to get my hands dirty on "bare metal" and a decent debugger makes life easier. So, here I am making another iteration of my preamp - this time involving no less than four TI processors. I have decided to post my project under the Tiva C header since it is the main workhorse, but the three other MCUs are 430s. Ok, enough rambling - here are the main components I have designed: Raspberry PI power switch - PC-style startup/shutdown, may be controlled over I2C or from a front panel switch. IR Remote Control - RC5 protocol. Main controller - Tiva C based, custom UI library and support for Keystone DAB radio. Preamp board, 5 line inputs with the option of switcing one to phono (magnetic cartridge - vinyl is getting popular again), DAB option, I2C control and still a VCA based volume control. I have recently switched to KiCad as my EDA, I did use Zenith PCB earlier but I am a bit scared to continue using that as it is licensed on a yearly basis (even if it is free) - who knows when it wil not be supported anymore. KiCad is open software and does not suffer from any limitations to number of pins or board size. Attached are the design files I have made for the Preamp board - the design is still to be verified, I will do that when I see how the controller board works out when arriving from the fabricator. 3D view from my KiCad design - I am too lazy to make my own 3D files so it is somewhat incomplete. There is a TI processor hidden on the bottom side, as is the KeyStone radio module. If everything goes to plan I will post about the bits and pieces that makes up the complete project. I even have mechanical design files (Vectric format) that may be used to make files in order fabricate the enclosures on a CNC-machine. Ok, enough for this time. Terje PreAmpBoard.zip
  14. From the tm4c1294, I thought I remembered only seeing 8 PWM pins, yet the Energia picture (http://energia.nu/wordpress/wp-content/uploads/2014/06/LaunchPads-LM4F-TM4C-%E2%80%94-Pins-Maps-13-34.jpeg) shows quite a bit more than that. Can you really get PWM on every pin marked for PWM on the Energia diagram, or is it a case of all of the pins marked being PWM capable but only get PWM on 8 of them?
  15. Please, How to use the ADC Sample Averaging Control (ADCSAC) of TIVA C EK-TM4C123GXL with Energia? I need to increase the amount of reading by sampling. Thanks
  16. Good morning. I have a DS3231 and I want do hibernate Tiva C and wake up It with the rtc alarm. I did the alarm configuration, but, I couldn't configurate the hibernation module using Energia IDE. The microcontroller will has some sensors and sd card. So, It has a cycle: wake up (with rtc alarm) > read the sensors > write the data > hibernate ^------------------------------------------------------------------------------
  17. I am developing data acquisition using TM4C123GXL with Energia. I able to acquire signal of 20hz even my ADC has sampling rate of 1M/s. I need suggestion regarding how to increase acqusition bandwidth(higher range frequency)....
  18. ahmedmos

    Keil C++ Compiler

    I have Keil uVision version 4. I would like to configure it so that I can compile C++ code as well. I believe I can only compile C at the moment. Can anyone help with that? Thanks
  19. hello, i'm new here, and i want to know how to use PLL to change the tiva C systeme clock frequency? thanks
  20. Hello, I have a question regarding communication between my Tiva C EK-TM4C123GXL lauchpad and a generic SD Card breakout board. Using: Energia 0101E0013 Windows 8.1 SD Library (SD_TM4C) 4 GB FujiFilm SD card I CAN get the ReadWrite demo program in the SD library to work sucessfully by wiring everything up according to the 1-page pinout diagram that came with my board for the SPI bus. Hardware wiring (SD breakout --> Launchpad): SDCS --> J2.9 / PA3 / 12 MOSI --> J2.6 / PB7 / 15 SCK --> J1.7 / PB4 / 7 MISO --> J2.7 / PB6 / 14 And then I change the ReadWrite code so that it looks like this: void setup() { ... ... ... pinMode(12, OUTPUT); pinMode(12, LOW); if (!SD.begin(12)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); ... ... ... } ...and everything works just fine. Here's where the problem comes in. I need to change the pins I'm using for the SD card because I'm going to use the Sensor Hub BoosterPack which uses (at least) J2.6 - J2.7 for I2C communication with the sensors. As far as my understanding goes, that means I need to find a different SPI bus for the SD card because I can't switch modes or devices easily. I have tried wiring up to pins J3.3 - J3.6 and changing my code to this... void setup() { ... ... ... pinMode(24, OUTPUT); pinMode(24, LOW); if (!SD.begin(24, SPI_HALF_SPEED, 3)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); ... ... ... } ... but the SD card never initializes correctly. I'm obviously missing something and/or not understanding this SP_TM4C library correctly. Any help would be amazing. Thank you!
  21. karatesever

    Big array in memory

    I'm using a Tiva C series TM4C123G and I need to write 2 arrays of about 30000 places each, and this can't be done on the RAM memory so I was wondering if I could use the Flash memory instead. Is there a better way to solve this problem? And does anybody have a piece of code showing how to assign a array to the flash memory? On the same matter, I will need to ADC sample between 10khz and 15Khz, is there enough time to write to the flash memory? My clock is set to 80Mhz.
  22. I'm trying to port the usb_host_msc example to the Tiva Launchpad (EK-TM4C123GXL). I've been struggling with setting up the paths/build variables correctly. Ever since I introduced a function that uses the third part FatFs library. #10010 errors encountered during linking; "usb_host_mass_storage.out" not built usb_host_mass_storage C/C++ Problem unresolved symbols remain usb_host_mass_storage C/C++ Problem unresolved symbol f_mount, first referenced in ./main.obj usb_host_mass_storage C/C++ Problem I've double-checked the project properties several times, but i'm unable to determine what the issue really is. I've attached an archived version of the project. I'm using versions of TivaWare. of Code Composer Studio 14.04 of Ubuntu Appreciate any help. ccs_usb_mass_storage_example_tm4c123gh6pm.zip
  23. i am using a tiva c 1294 and the latest version of Energia. what i need to do is to be able to send information i get from the ADC via the Ethernet. that being said i already have a working version of the ADC, and right now i am just trying to get the Ethernet working. i figured that since i really only need to send the collected data out that sending it using UDP would be best since i haven't really worked with many Ethernet applications and i from what i know UDP is the simplest. I loaded the program listed under: File>Examples>Ethernet>UDPSendReceiveString (where the underlined portion is the actual program) and I tried to follow the directions listed in it to change the mac address and " Here's using netcat to send udp echo -n "foo" | nc -4u -q1 8888 " but I am getting nothing. the tiva c is connected to my laptop with a crossover cable. I am using wireshark to try to capture the packets and I am capturing everything that isn't the wireless. I thnk that there might be something else I need to do with the cmd prompt but I don't know what... help?! ~Zack49 udpsendreceive.txt
  24. DrWizard

    Noob question: Floating Point

    Hello! I'm an Arduino old timer, been working with it for years, but I am new to this platform. I bought one of the new 'Connected Launchpads' with the ARM Cortex M4 (TM4C1294NCPDTI) microcontroller. Part of what tempted me to try this one is that it is supposed to have floating point support in the processor hardware. (Correct?) I have been working on a celestial clock that calculates sunrise, sunset, moonrise, set, phase, precise angles in the skies, tides, and various other astrological events, and displays it on a small LCD. It uses a cheap GPS module for the user's location and accurate time. And it uses a MP3 module to announce things. This was wayyyyyy to much floating point math and string manipulation for the 16MHz 8-bit Arduino to perform in any timely manner. I've been skimming thru the documentation and these forums and have seen little mention of the floating point support. Do the Energia and Code Composer compilers handle and optimize for this automatically? Or will I have to jump thru a hoop or two? Can someone please aim me in the direction of some more detailed documentation or examples? P.S. Yes, I will be sharing this project and it's code when I get a little further along with it!
  25. Niral1426459960

    I2C in Tiva C

    Hello community members.. I am trying to interface MMA7455 digital accelerometer with my Tiva C launchpad..I am using this code for interfacing. I have tested code provided in that link on my arduino uno and its working perfectly fine and give accurate value. Now, I have used same code in Energia and connected MMA7455 at I2C module-3 which is default module in Tiva C launchpad. My problem is the acceleration values in particular direction I am getting is some random garbage value. This is my first time encounter with Energia. Please help me to resolve my problem. I have connected two 4.7k pull up resistors at I2C bus. Code: // MMA7455 Accelerometer // --------------------- // // By arduino.cc user "Krodal". // May 2012 // Open Source / Public Domain // // Using Arduino 1.0.1 // It will not work with an older version, since Wire.endTransmission() // uses a parameter to hold or release the I2C bus. // // Documentation: // - The Freescale MMA7455L datasheet // - The AN3468 Application Note (programming). // - The AN3728 Application Note (calibrating offset). // // The MMA7455 can be used by writing and reading a single byte, // but it is also capable to read and write multiple bytes. // // The accuracy is 10-bits. // #include <Wire.h> // Register names according to the datasheet. // Register 0x1C is sometimes called 'PW', and sometimes 'PD'. // The two reserved registers can not be used. #define MMA7455_XOUTL 0x00 // Read only, Output Value X LSB #define MMA7455_XOUTH 0x01 // Read only, Output Value X MSB #define MMA7455_YOUTL 0x02 // Read only, Output Value Y LSB #define MMA7455_YOUTH 0x03 // Read only, Output Value Y MSB #define MMA7455_ZOUTL 0x04 // Read only, Output Value Z LSB #define MMA7455_ZOUTH 0x05 // Read only, Output Value Z MSB #define MMA7455_XOUT8 0x06 // Read only, Output Value X 8 bits #define MMA7455_YOUT8 0x07 // Read only, Output Value Y 8 bits #define MMA7455_ZOUT8 0x08 // Read only, Output Value Z 8 bits #define MMA7455_STATUS 0x09 // Read only, Status Register #define MMA7455_DETSRC 0x0A // Read only, Detection Source Register #define MMA7455_TOUT 0x0B // Temperature Output Value (Optional) #define MMA7455_RESERVED1 0x0C // Reserved #define MMA7455_I2CAD 0x0D // Read/Write, I2C Device Address #define MMA7455_USRINF 0x0E // Read only, User Information (Optional) #define MMA7455_WHOAMI 0x0F // Read only, "Who am I" value (Optional) #define MMA7455_XOFFL 0x10 // Read/Write, Offset Drift X LSB #define MMA7455_XOFFH 0x11 // Read/Write, Offset Drift X MSB #define MMA7455_YOFFL 0x12 // Read/Write, Offset Drift Y LSB #define MMA7455_YOFFH 0x13 // Read/Write, Offset Drift Y MSB #define MMA7455_ZOFFL 0x14 // Read/Write, Offset Drift Z LSB #define MMA7455_ZOFFH 0x15 // Read/Write, Offset Drift Z MSB #define MMA7455_MCTL 0x16 // Read/Write, Mode Control Register #define MMA7455_INTRST 0x17 // Read/Write, Interrupt Latch Reset #define MMA7455_CTL1 0x18 // Read/Write, Control 1 Register #define MMA7455_CTL2 0x19 // Read/Write, Control 2 Register #define MMA7455_LDTH 0x1A // Read/Write, Level Detection Threshold Limit Value #define MMA7455_PDTH 0x1B // Read/Write, Pulse Detection Threshold Limit Value #define MMA7455_PD 0x1C // Read/Write, Pulse Duration Value #define MMA7455_LT 0x1D // Read/Write, Latency Time Value (between pulses) #define MMA7455_TW 0x1E // Read/Write, Time Window for Second Pulse Value #define MMA7455_RESERVED2 0x1F // Reserved // Defines for the bits, to be able to change // between bit number and binary definition. // By using the bit number, programming the MMA7455 // is like programming an AVR microcontroller. // But instead of using "(1<<X)", or "_BV(X)", // the Arduino "bit(X)" is used. #define MMA7455_D0 0 #define MMA7455_D1 1 #define MMA7455_D2 2 #define MMA7455_D3 3 #define MMA7455_D4 4 #define MMA7455_D5 5 #define MMA7455_D6 6 #define MMA7455_D7 7 // Status Register #define MMA7455_DRDY MMA7455_D0 #define MMA7455_DOVR MMA7455_D1 #define MMA7455_PERR MMA7455_D2 // Mode Control Register #define MMA7455_MODE0 MMA7455_D0 #define MMA7455_MODE1 MMA7455_D1 #define MMA7455_GLVL0 MMA7455_D2 #define MMA7455_GLVL1 MMA7455_D3 #define MMA7455_STON MMA7455_D4 #define MMA7455_SPI3W MMA7455_D5 #define MMA7455_DRPD MMA7455_D6 // Control 1 Register #define MMA7455_INTPIN MMA7455_D0 #define MMA7455_INTREG0 MMA7455_D1 #define MMA7455_INTREG1 MMA7455_D2 #define MMA7455_XDA MMA7455_D3 #define MMA7455_YDA MMA7455_D4 #define MMA7455_ZDA MMA7455_D5 #define MMA7455_THOPT MMA7455_D6 #define MMA7455_DFBW MMA7455_D7 // Control 2 Register #define MMA7455_LDPL MMA7455_D0 #define MMA7455_PDPL MMA7455_D1 #define MMA7455_DRVO MMA7455_D2 // Interrupt Latch Reset Register #define MMA7455_CLR_INT1 MMA7455_D0 #define MMA7455_CLR_INT2 MMA7455_D1 // Detection Source Register #define MMA7455_INT1 MMA7455_D0 #define MMA7455_INT2 MMA7455_D1 #define MMA7455_PDZ MMA7455_D2 #define MMA7455_PDY MMA7455_D3 #define MMA7455_PDX MMA7455_D4 #define MMA7455_LDZ MMA7455_D5 #define MMA7455_LDY MMA7455_D6 #define MMA7455_LDX MMA7455_D7 // I2C Device Address Register #define MMA7455_I2CDIS MMA7455_D7 // Default I2C address for the MMA7455 #define MMA7455_I2C_ADDRESS 0x1D // When using an union for the registers and // the axis values, the byte order of the accelerometer // should match the byte order of the compiler and AVR chip. // Both have the lower byte at the lower address, // so they match. // This union is only used by the low level functions. typedef union xyz_union { struct { uint8_t x_lsb; uint8_t x_msb; uint8_t y_lsb; uint8_t y_msb; uint8_t z_lsb; uint8_t z_msb; } reg; struct { int x; int y; int z; } value; }; void setup() { int error; uint8_t c; Serial.begin(9600); Serial.println(F("Freescale MMA7455 accelerometer")); Serial.println(F("May 2012")); // Initialize the 'Wire' class for I2C-bus communication. Wire.begin(); // Initialize the MMA7455, and set the offset. error = MMA7455_init(); if (error == 0) Serial.println(F("The MMA7455 is okay")); else Serial.println(F("Check your wiring !")); // Read the Status Register MMA7455_read(MMA7455_STATUS, &c, 1); Serial.print(F("STATUS : ")); Serial.println(c,HEX); // Read the "Who am I" value MMA7455_read(MMA7455_WHOAMI, &c, 1); Serial.print(F("WHOAMI : ")); Serial.println(c,HEX); // Read the optional temperature output value (I always read zero) MMA7455_read(MMA7455_TOUT, &c, 1); Serial.print(F("TOUT : ")); Serial.println(c,DEC); } void loop() { int x,y,z, error; double dX,dY,dZ; // The function MMA7455_xyz returns the 'g'-force // as an integer in 64 per 'g'. // set x,y,z to zero (they are not written in case of an error). x = y = z = 0; error = MMA7455_xyz(&x, &y, &z); // get the accelerometer values. dX = (double) x / 64.0; // calculate the 'g' values. dY = (double) y / 64.0; dZ = (double) z / 64.0; Serial.print(F("error = ")); Serial.print(error, DEC); Serial.print(F(", xyz g-forces = ")); Serial.print(dX, 3); Serial.print(F(", ")); Serial.print(dY, 3); Serial.print(F(", ")); Serial.print(dZ, 3); Serial.println(F("")); delay(1000); } // -------------------------------------------------------- // MMA7455_init // // Initialize the MMA7455. // Set also the offset, assuming that the accelerometer is // in flat horizontal position. // // Important notes about the offset: // The sensor has internal registers to set an offset. // But the offset could also be calculated by software. // This function uses the internal offset registers // of the sensor. // That turned out to be bad idea, since setting the // offset alters the actual offset of the sensor. // A second offset calculation had to be implemented // to fine tune the offset. // Using software variables for the offset would be // much better. // // The offset is influenced by the slightest vibration // (like a computer on the table). // int MMA7455_init(void) { int x, y, z, error; xyz_union xyz; uint8_t c1, c2; // Initialize the sensor // // Sensitivity: // 2g : GLVL0 // 4g : GLVL1 // 8g : GLVL1 | GLVL0 // Mode: // Standby : 0 // Measurement : MODE0 // Level Detection : MODE1 // Pulse Detection : MODE1 | MODE0 // There was no need to add functions to write and read // a single byte. So only the two functions to write // and read multiple bytes are used. // Set mode for "2g sensitivity" and "Measurement Mode". c1 = bit(MMA7455_GLVL0) | bit(MMA7455_MODE0); error = MMA7455_write(MMA7455_MCTL, &c1, 1); if (error != 0) return (error); // Read it back, to test the sensor and communication. error = MMA7455_read(MMA7455_MCTL, &c2, 1); if (error != 0) return (error); if (c1 != c2) return (-99); // Clear the offset registers. // If the Arduino was reset or with a warm-boot, // there still could be offset written in the sensor. // Only with power-up the offset values of the sensor // are zero. xyz.value.x = xyz.value.y = xyz.value.z = 0; error = MMA7455_write(MMA7455_XOFFL, (uint8_t *) &xyz, 6); if (error != 0) return (error); // The mode has just been set, and the sensor is activated. // To get a valid reading, wait some time. delay(100); #define USE_INTERNAL_OFFSET_REGISTERS #ifdef USE_INTERNAL_OFFSET_REGISTERS // Calcuate the offset. // // The values are 16-bits signed integers, but the sensor // uses offsets of 11-bits signed integers. // However that is not a problem, // as long as the value is within the range. // Assuming that the sensor is flat horizontal, // the 'z'-axis should be 1 'g'. And 1 'g' is // a value of 64 (if the 2g most sensitive setting // is used). // Note that the actual written value should be doubled // for this sensor. error = MMA7455_xyz (&x, &y, &z); // get the x,y,z values if (error != 0) return (error); xyz.value.x = 2 * -x; // The sensor wants double values. xyz.value.y = 2 * -y; xyz.value.z = 2 * -(z-64); // 64 is for 1 'g' for z-axis. error = MMA7455_write(MMA7455_XOFFL, (uint8_t *) &xyz, 6); if (error != 0) return (error); // The offset has been set, and everything should be okay. // But by setting the offset, the offset of the sensor // changes. // A second offset calculation has to be done after // a short delay, to compensate for that. delay(200); error = MMA7455_xyz (&x, &y, &z); // get te x,y,z values again if (error != 0) return (error); xyz.value.x += 2 * -x; // add to previous value xyz.value.y += 2 * -y; xyz.value.z += 2 * -(z-64); // 64 is for 1 'g' for z-axis. // Write the offset for a second time. // This time the offset is fine tuned. error = MMA7455_write(MMA7455_XOFFL, (uint8_t *) &xyz, 6); if (error != 0) return (error); #endif return (0); // return : no error } // -------------------------------------------------------- // MMA7455_xyz // // Get the 'g' forces. // The values are with integers as 64 per 'g'. // int MMA7455_xyz( int *pX, int *pY, int *pZ) { xyz_union xyz; int error; uint8_t c; // Wait for status bit DRDY to indicate that // all 3 axis are valid. do { error = MMA7455_read (MMA7455_STATUS, &c, 1); } while ( !bitRead(c, MMA7455_DRDY) && error == 0); if (error != 0) return (error); // Read 6 bytes, containing the X,Y,Z information // as 10-bit signed integers. error = MMA7455_read (MMA7455_XOUTL, (uint8_t *) &xyz, 6); if (error != 0) return (error); // The output is 10-bits and could be negative. // To use the output as a 16-bit signed integer, // the sign bit (bit 9) is extended for the 16 bits. if (xyz.reg.x_msb & 0x02) // Bit 9 is sign bit. xyz.reg.x_msb |= 0xFC; // Stretch bit 9 over other bits. if (xyz.reg.y_msb & 0x02) xyz.reg.y_msb |= 0xFC; if (xyz.reg.z_msb & 0x02) xyz.reg.z_msb |= 0xFC; // The result is the g-force in units of 64 per 'g'. *pX = xyz.value.x; *pY = xyz.value.y; *pZ = xyz.value.z; return (0); // return : no error } // -------------------------------------------------------- // MMA7455_read // // This is a common function to read multiple bytes // from an I2C device. // // It uses the boolean parameter for Wire.endTransMission() // to be able to hold or release the I2C-bus. // This is implemented in Arduino 1.0.1. // // Only this function is used to read. // There is no function for a single byte. // int MMA7455_read(int start, uint8_t *buffer, int size) { int i, n, error; Wire.beginTransmission(MMA7455_I2C_ADDRESS); n = Wire.write(start); if (n != 1) return (-10); n = Wire.endTransmission(false); // hold the I2C-bus if (n != 0) return (n); // Third parameter is true: relase I2C-bus after data is read. Wire.requestFrom(MMA7455_I2C_ADDRESS, size, true); i = 0; while(Wire.available() && i<size) { buffer[i++]=Wire.read(); } if ( i != size) return (-11); return (0); // return : no error } // -------------------------------------------------------- // MMA7455_write // // This is a common function to write multiple bytes // to an I2C device. // // Only this function is used to write. // There is no function for a single byte. // int MMA7455_write(int start, const uint8_t *pData, int size) { int n, error; Wire.beginTransmission(MMA7455_I2C_ADDRESS); n = Wire.write(start); // write the start address if (n != 1) return (-20); n = Wire.write(pData, size); // write data bytes if (n != size) return (-21); error = Wire.endTransmission(true); // release the I2C-bus if (error != 0) return (error); return (0); // return : no error }