window Watchdog Timer STM32F4 - c

Edited
DONE NOW .. I'll reconstruct the code, but now it's done and tested
I need to implement a timer that checks for conditions every x sec .. the problem I face that the program doesn't reset when it enters infinite loop ( away for check like if the system has been halted) ...
these links helped me .. manual from page 74 http://www2.st.com/content/ccc/resource/technical/document/reference_manual/3d/6d/5a/66/b4/99/40/d4/DM00031020.pdf/files/DM00031020.pdf/jcr:content/translations/en.DM00031020.pdf ..
and this link http://www.programmershare.com/3518407/
thanks in advance
I currently have this code :
#include "stm32f4xx.h"
#include <stm32f4xx_gpio.h>
#include <stm32f4xx_rcc.h>
#include <stm32f4xx_wwdg.h>
void setup_Periph(void);
void Delay(unsigned long ms);
void Delay(unsigned long ms)
{ unsigned long i,j;
for(i=0;i<ms;i++)
for(j=0;j<1450;j++);
}
void setup_Periph(void)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
//port initialization
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_Init(GPIOD,&GPIO_InitStructure);
}
void ResetWatchdog(void)
{ WWDG_SetCounter(80);}
void WWDG_IRQHandler(void)
{
if (WWDG_GetFlagStatus())
{
WWDG_SetCounter(0x7f);
WWDG_ClearFlag();
}
}
void FeedDog(float round)
{
while(round)
{ Delay (65);
WWDG_SetCounter(127);
round--;}
}
int main(void)
{
//RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
//System Clock auf Watchdog
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
WWDG_SetPrescaler(WWDG_Prescaler_8);
//WWDG clock counter = (PCLK1(30MHz)/4096)/1 = 7324 Hz (~137 us)
WWDG_SetCounter(80); //Werte 0x40 und 0x7F
WWDG_SetWindowValue(80); //0x80
//Reset < 120 > 64
WWDG_Enable(127); //WWDG timeout = ~137 us * (127-64) = 8.6ms
WWDG_ClearFlag();
WWDG_EnableIT();
setup_Periph();
//make sure the clk is stable
RCC_HSEConfig(RCC_HSE_ON);
while(!RCC_WaitForHSEStartUp());
GPIO_SetBits(GPIOD, GPIO_Pin_1);
Delay(10000); //10 ms
GPIO_ResetBits(GPIOD, GPIO_Pin_1);
Delay(10000); //100 ms
while (1)
{
GPIO_SetBits(GPIOD, GPIO_Pin_0);
Delay(10000); //10 ms
GPIO_ResetBits(GPIOD, GPIO_Pin_0);
Delay(10000); //100 ms
void ResetWatchdog(void);
WWDG_SetCounter(80);
FeedDog(8);
for(;;) {}
}
}

There are several things very obviously wrong here. Most troubling among them are:
Your Delayms() function does not implement any kind of delay. It appears to configure one of the LEDs to flash.
You are never calling InitWatchdog(). (Instead, you are declaring its prototype within main() for some reason.)
I don't want this to sound too harsh, but: do you know C? This code reads as though it's been put together by copying and pasting pieces from examples without understanding them. If you do not know C, attempting to develop software for an embedded system is not an effective way to learn it, especially without guidance.

Related

Pic 18f4550 capture mode

I would like to measure a pulse using the pic 18f4550 in capture mode, this pulse is generated by the pic microcontroller itself, for this I use a function which plays the role of the XOR logic gate (you find the function that I've used below). with RC0 and RC2 the inputs and RC6 the signal output. the pulse leaving RC6 enters ccp2 to be measured.
The problem I found is that the ccp2 cannot detect the impulse generated by the microcontroller. I don't know if there are any conditions to connect the pins of the microcontroller or something.
If anyone has an answer or a hint to fix this, I will be grateful!
and if you have any questions feel free to ask .thanks !!
UPDATE: I changed some instructions in the code, now the RC6 output provides a signal. but my LCD does not display anything. the RC6 output is present below.
UPDATE 2: the while(1) in the xor() function blocking the rest of my program, so the program never get out of xor() and my LCD wont display anything. when I don't use the while loop in xor () my RC6 produce anything, the same for the LCD.
I don't know where the problem is, I did everything in my power to find the bug . but the system still not working!!!
I will leave the program as it is, so new readers can understand what I am talking about.
#include <stdio.h>
#include <stdlib.h>
#include "osc_config.h"
#include "LCD_8bit_file.h"
#include <string.h>
unsigned long comtage,capt0,x;
char pulse[20];
char cosinus[20];
float period,dephTempo,deph,phi;
void init (){
IRCF0 =1; /* set internal clock to 8MHz */
IRCF1 =1;
IRCF2 =1;
PIE2bits.CCP2IE=1;
PIR2bits.CCP2IF=0;
CCPR2 =0; /*CCPR1 is capture count Register which is cleared initially*/
T3CONbits.RD16=1;
T3CKPS0=0;
T3CKPS1=0;
TMR3CS=0;
TMR3IF=0;
T3CCP2=0; /*Timer3 is the capture clock source for CCP2*/
}
void xor()
{
while(1)
{
if (PORTCbits.RC0==PORTCbits.RC2)
{
PORTCbits.RC6=0;
}
else if (PORTCbits.RC0!=PORTCbits.RC2)
{
PORTCbits.RC6=1;
}
}
}
void main()
{
TRISCbits.TRISC0=1;
TRISCbits.TRISC2=1;
TRISCbits.TRISC6=0;
xor();
LCD_Init();
while(1)
{
CCP2CON = 0b00000101;
PIR2bits.CCP2IF = 0;
TMR3ON = 0;
TMR3 = 0;
while (!PIR2bits.CCP2IF);
TMR3ON = 1;
CCP2CON = 0b00000100;
PIR2bits.CCP2IF = 0;
while (!PIR2bits.CCP2IF);
comtage = CCPR2;
dephTempo = (((float)comtage /30.518)/65536 );
sprintf(pulse,"%.3f ",dephTempo);
LCD_String_xy(0,0,"the pulse width is : ");
LCD_String_xy(2,9,pulse);
}
}

Audio Transfer Callbacks not executing with STM32F469I-Discovery

I'm new to embedded programming and I'm currently working on a project with an STM32F469I-discovery board. I'm using eclipse with the ARM tool chain and the supplied drivers. I'm getting stuck on playing a binary audio file flashed into the chip at a specific address. I've very simply based my code on some of the example files, although very much cut down as I'm just trying to get it to work.
At the moment, the code works up to the point where it plays the buffer, but then it appears to get stuck. The buffer is playing in a loop (I've changed the size of the buffer to confirm this) and you can hear it, but that's all that happens. The transfer interrupt callbacks never execute, and hence the buffer does not refil and the full sample is never played.
I've tried using an external interupt to refil the buffer, but when I try this, it gets stuck. I've also tried to debug it by turning on LEDs, but this has confirmed that effectively it gets stuck shortly after playing the sample. The infinite while loop never executes, and the transfer interrupts never execute.
My question is - why is it getting stuck and why are the interrupts not being triggered?
Any help would be greatly appreciated!
#include "main.h"
static void SystemClock_Config(void);
#define AUDIO_FILE_ADDRESS 0x08010000
#define AUDIO_FILE_SIZE (180*1024)
#define PLAY_HEADER 0x2C
#define PBSIZE 4096
uint16_t PlayBuff[PBSIZE];
int OFFSET = 0;
int TransferState = 0;
int CycleCount1 = 1;
int CycleCount2 = 1;
int main(void)
{
uint32_t PlaybackPosition = PBSIZE + PLAY_HEADER;
HAL_Init();
/* Configure the system clock to 180 MHz */
SystemClock_Config();
// Fill the buffer first time round
for(int i=0; i <= PBSIZE; i++)
{
PlayBuff[i]=*((__IO uint16_t *)(AUDIO_FILE_ADDRESS + PLAY_HEADER + i));
}
BSP_AUDIO_OUT_Init(2,50,AUDIO_FREQUENCY_16K );
BSP_AUDIO_OUT_Play(PlayBuff,PBSIZE);
while(1){
if(TransferState==1){
// refill the first part of the buffer
TransferState=0;
OFFSET = CycleCount1*PBSIZE;
for(int i=0; i <= PBSIZE/2; i++){
PlayBuff[i]=*((__IO uint16_t *)(AUDIO_FILE_ADDRESS + PLAY_HEADER + OFFSET));
}
CycleCount1++;
}
if(TransferState==2){
// refill the second part of the buffer
OFFSET = CycleCount2*PBSIZE+PBSIZE;
TransferState=0;
for(int i=PBSIZE/2; i <= PBSIZE; i++){
PlayBuff[i]=*((__IO uint16_t *)(AUDIO_FILE_ADDRESS + PLAY_HEADER + OFFSET));
}
CycleCount2++;
}
}
}
void BSP_AUDIO_OUT_TransferComplete_CallBack(void)
{
TransferState=2;
}
void BSP_AUDIO_OUT_HalfTransfer_CallBack(void){
TransferState=1;
}
In the interests of identifying the cause of the problem, I've further trimmed down the code so that all it does is play the buffer. I've removed the interrupt calls to try and identify what's causing the issue.
What it should do is configure the system clock, fill the buffer, initialise the audio, then turn on the LED. It should then play the audio buffer, wait 1s, then turn off the LED. It plays the buffer in a loop (as it should as it's in circular mode) but then gets stuck and never turns off the LED. I've tried running it in normal mode but it simply plays the buffer once, and then gets stuck.
This leads me to think I've configured/filled the buffer incorrectly.
#include "main.h"
static void SystemClock_Config(void);
#define AUDIO_FILE_ADDRESS 0x08010000
#define PLAY_HEADER 0x17569
#define PBSIZE 4096
uint16_t PlayBuff[PBSIZE];
int main(void)
{
BSP_LED_Init(LED1);
HAL_Init();
/* Configure the system clock to 180 MHz */
SystemClock_Config();
// Fill the buffer first time round
for(int i=0; i <= PBSIZE; i++)
{
PlayBuff[i]=*((__IO uint16_t *)(AUDIO_FILE_ADDRESS + PLAY_HEADER + i));
}
BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE ,50,AUDIO_FREQUENCY_44K );
BSP_LED_On(LED1);
BSP_AUDIO_OUT_Play(PlayBuff,PBSIZE);
HAL_Delay(1000);
BSP_LED_Off(LED1);
}
Furthermore, I've also found instances of other people online having similar issues although with no solution so far. Any help would be greatly appreciated.
I've found the problem. I hadn't set the DMA interupt in the stm32f4xx_it.c.
void DMA2_Stream3_IRQHandler(void)
{
HAL_DMA_IRQHandler(haudio_out_sai.hdmatx);
}
I've also found that when using BSP_AUDIO_OUT_Play() the sound is wrong with something bassy fluctating underneath it.
Using the following worked correctly.
/* Start the playback */
if(0 != audio_drv->Play(AUDIO_I2C_ADDRESS, NULL, 0))
{
Error_Handler();
}
if(HAL_OK != HAL_SAI_Transmit_DMA(&haudio_out_sai, (uint8_t *) PlayBuff, PLAY_BUFF_SIZE))
{
Error_Handler();
}
I am not familiar with the specific board, from what i see possibly you need to define TransferState as volatile.
volatile int TransferState = 0;
It is quite common issue in embedded and multi-threaded development. The compiler can optimize the variable TransferState in a register so it never actually sees the update from a different context(the callback). Volatile prevents it from doing so

How can I run two loops at the same time?

I have written code that makes LEDs blinks and moves a servo to several different directions. Here's the basic structure:
while(true){
//led on
//wait
//led off
//wait
}
while(true){
//servo to 45
//servo to 90
//servo to 270
}
I want both to run at the same time. The code above only turns on the LEDs, and infinitely since it's in the loop. The servo never works. I looked at other questions on here but I couldn't find anything relevant.
How can I make both the LEDs and servo work at the same time?
In general you cannot use two infinite loops. That's because it is senquentional program, so it cannot run second when until the first one is done. So if first loop is infinite, the second will never run.
To do some kind of 'multithreading', in simplest way is to use timers and interrupts.
In your case you want to run two different task. Blinking led and steering servos. When you use wait()/sleep()/delay(), the uC is simply stopping (except handling other things like interupts etc.). So you can set timers and in the interrupt blink led. Or better in the interrupt just set some flag, and in your main just check if flag has changed. Than just handle blink. So in general you will have in you main sth like this:
volatile uint8_t nowBlink = 0
ISR(TIMER1_OVF_vect)
{
// some timer handling and then:
nowBlink = 1
}
loop(){
if(nowBlink){
toggleLed();
nowBlink = 0;
}
setServo(123123);
}
Setting intterupt to 1 s, will blink your led with freq of 1 Hz, and then other parts of program will be done.
Here you have timers explained, and Here you have some libraries. Just read that and you should be master of arduino.
Best regards, voodoo16.
Don't use functions like delay_ms(), wait () etc. Try interrupt.
Use the struture like this :
int flag = 0;
void func_delay_50ms () interrupt
{
// set initial condition
flag ++;
}
void main
{
while (1)
{
if (flag == 4) // per 200ms
{
led = -led;
flag = 0;
}
if (!(flag % 2)) // per 100ms
{
servo ();
}
}
}
note : servo () should not block for a long time.
There are no really conturrent threads, And you should create an illusion to realize it.
(:з」∠) My poor English. pardon me.
Blinking a LED does not really require code on the MCU. You can use a timer and a PWM signal. https://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM
I wrote an Operating System for Arduino which supports multithreading in order to run multiple loops at once. Note that the servo has a range from 0-180. You can't turn in 270 degrees. You can find the source and further documentation here https://github.com/DrBubble/ArduinoOS.
This example code should do exactly what you want when running under the ArduinoOS.
#include "KernelInitializer.h"
#include "Servo.h"
#include "Led.h"
void setup()
{
KernelInitializer::InitializeKernel(mainThread);
}
void mainThread()
{
InitTask(secondThread);
while (true)
{
Led led(2); // replace 2 with the pin of your led
while (true)
{
led.TurnOn();
sleep(1000);
led.TurnOff();
sleep(1000);
}
}
}
void secondThread()
{
Servo servo(9); // replace 9 with the pin of your servo
while (true)
{
servo.SetValue(45);
sleep(1000);
servo.SetValue(90);
sleep(1000);
servo.SetValue(180);
sleep(1000);
}
}
You can simply use a goto statement
in both the loop.....you dont even need a loop if you use goto, like in assembly language.
c code for it is:
#include<stdio.h>
int main()
{
int count;
loop1:for(;;)
{
printf("Loop 1\n");
goto loop2;
}
loop2:for(;;)
{
printf("Loop 2\n");
goto loop1;
}
return 0;
}

Programming a XM1000 Sensor Device in C Programming Language Need if statement

I am programming a sensor mote (XM1000) I am using Contiki Operating System to program this devices ( I am using terminal to view the outputs and GEdit to write my 'C' code in. This sensor mote has a temprature, light and humidity sensor on board as well as 3 LED lights.
Below I have two sets of code. The first set of code functions and gives me the sensor readings for the values for temprature, light and humidity.
The second set of code functions. it turns the LED lights on/off and makes them blinking regularly on the sensor node XM1000, it counts how many times the LED has blinked and output the count to the console.
The problem I am having is creating a if statement to meet these following conditions and I am struggling to combine the two codes together. So this is what I want to achieve:
• If the temperature exceeds over 26 Degrees then turn on LED Light 1 for 5 seconds, else if the temperature is equal to and below 26 Degrees then turn off LED Light 1.
• If the Humidity exceeds over 40% then turn on LED Light 2 for 5 seconds, else if the humidity is equal to and below 40% then turn off LED Light 2.
• If the Light intensity exceeds over 510 nanometres then turn on LED Light 3 for 5 seconds, else if the light intensity is equal to and below 510nm then turn off LED Light 3.
First Set of Code: It measures the temprature, light and humidity and outputs the results on a terminal window.
#include "contiki.h" //Contiki Header File
#include "dev/light-sensor.h" //Light Sensor Header File
#include "dev/sht11-sensor.h" //Temperature and Humidity Header File
#include <stdio.h> /* for printf() */ // standard input/output library needed to write to the standard output
static struct etimer timer; //Process Requires a Timer
int light=0, temp=0, humid=0;
//To Start
/*___________________________________________________*/
PROCESS(sensor_reading_process, "Sensor Reading Process");
AUTOSTART_PROCESSES(&sensor_reading_process);
/*___________________________________________________*/
//PROCESS BEGINS
PROCESS_THREAD(sensor_reading_process, ev, data)
{
PROCESS_BEGIN();
SENSORS_ACTIVATE(light_sensor); //Activate the Light Sensor
SENSORS_ACTIVATE(sht11_sensor);//Activate Temp/Humidity Sensor
etimer_set(&timer, CLOCK_CONF_SECOND);//Configuring Timer 1SEC
while(1) { //Start of While Loop
PROCESS_WAIT_EVENT_UNTIL(ev==PROCESS_EVENT_TIMER);//Wait4Time
// This is how we get the Sensor Values for light, temp, hum
light = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
temp = sht11_sensor.value(SHT11_SENSOR_TEMP);
humid = sht11_sensor.value(SHT11_SENSOR_HUMIDITY);
printf("Light=%d, Temp=%d, Humid=%d\n", light, temp, humid);
//Above Line if Print Plus Values
etimer_reset(&timer); //Reset the Timer
}
PROCESS_END(); //End of Process
}
The second code:
#include "contiki.h"
#include "leds.h" // LED HEADER FILE
#include <stdio.h> /* for printf() */
static struct etimer timer;
/*____________________________________________________*/
PROCESS(led_blinking_process, "LED Blinking Process");
PROCESS(LED_process, "LED process");
AUTOSTART_PROCESSES(&LED_process);
/*____________________________________________________*/
PROCESS_THREAD(LED_process, ev, data)
{
static int count = 0;
PROCESS_BEGIN();
etimer_set(&timer, CLOCK_CONF_SECOND/2); // 0.5S timer
leds_init(); // initialise the LEDs
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev==PROCESS_EVENT_TIMER); // wait for timer event
count++; // count the blinking times
process_start(&led_blinking_process, NULL); // to blink the BLUE Led
printf("Count: %d\n", count); // output the counter number to console
etimer_reset(&timer); // reset the timer
}
PROCESS_END();
}
CODE FOR LED LIGHTS
/*____________________________________________________*/
PROCESS_THREAD(led_blinking_process, ev, data)
{
PROCESS_BEGIN();
leds_toggle(LEDS_BLUE); // Blinking the Blue LED
PROCESS_END();
}
Please note both codes work when I run them , I am just trying to combine them , use a if statement so i can meet my functions I have stated above.
Thanks in advance for any help or contributions!
Here's what I think it will look like, give or take a little hacking. I've structured the code as a single loop, that just polls all three sensors at 5 second intervals. So every 5 seconds, the on/off status of all three lights might change. I figure for watering a lawn, you don't really need split-second precision in terms of knowing when it got hot, or dark, or whatever.
Based on your replies in the comments section of the OP, there might have to be some computation done involving the return values of the sensor readings. I figure it's probably easier to do the computation at compile time, so the code is biased that way.
#include <stdio.h> /* for printf() */
#include "contiki.h"
#include "leds.h"
#include "dev/light-sensor.h"
#include "dev/sht11-sensor.h"
PROCESS(Led_management_process, "LED Management Process");
AUTOSTART_PROCESSES(&Led_management_process);
static struct etimer Timer;
/* Per the online docs at http://www.advanticsys.com/wiki/index.php?title=TestCM5000
T = -39.6 + 0.01 × SO(T)
So, solving for SOt gives:
*/
#define degreesC(n) (n)
#define TEMP_D1 degreesC(-39.6)
#define TEMP_D2 degreesC(0.01)
#define TEMP_THRESHOLD(tempC) (int)(((((double)(tempC))-(TEMP_D1))/(TEMP_D2)))
#define TARGET_TEMP_READING TEMP_THRESHOLD(degreesC(26))
#define LIGHT_LED LEDS_GREEN
#define HUM_LED LEDS_BLUE
#define TEMP_LED LEDS_RED
PROCESS_THREAD(Led_management_process, ev, data)
{
static int humidity_led_on = 0;
static int light_led_on = 0;
static int temp_led_on = 0;
PROCESS_BEGIN();
SENSORS_ACTIVATE(light_sensor);
SENSORS_ACTIVATE(sht11_sensor);
leds_init();
unsigned int cycle = 0;
while (1) {
printf("%8u:", cycle);
/* This part is questionable, since I don't know if the
sensors are guaranteed to return ints (vs. floats or
something) and I don't know what units they use. */
int temp = sht11_sensor.value(SHT11_SENSOR_TEMP);
if (temp > TARGET_TEMP_READING) {
printf(" TEMP warm- ");
if (!temp_led_on) {
printf("toggle LED");
temp_led_on = 1;
leds_toggle(TEMP_LED);
}
else {
printf("LED is ok ");
}
}
else {
printf(" TEMP cold- ");
if (temp_led_on) {
printf("toggle LED");
temp_led_on = 0;
leds_toggle(TEMP_LED);
}
else {
printf("LED is ok ");
}
}
/* Code for humidity */
/* Code for light */
printf("\n");
/* Sleep 5 seconds */
etimer_set(&Timer, CLOCK_CONF_SECOND * 5);
PROCESS_WAIT_EVENT_UNTIL(ev==PROCESS_EVENT_TIMER);
etimer_reset(&Timer);
++cycle;
}
PROCESS_END();
}

TIva C Series problems with I2C Interface

I'm currently trying to interface my Tiva C Series with a Sparkfun Breakout Board, IMU Digital Combo Board - 6 Degrees of Freedom ITG3200/ADXL345 and I'm having trouble with the I2C interface.
currently this is my code:
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"
uint8_t SLAVE_ADDRESS = 0x68;
uint32_t first_byte, second_byte, temperature, result;
void i2c_setup(void) {
//Enable the I2C Module
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C2);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
//Wait at least 5 clock cycles
SysCtlDelay(2);
//Configure SDA and SCL
GPIOPinConfigure(GPIO_PE4_I2C2SCL);
GPIOPinConfigure(GPIO_PE5_I2C2SDA);
//Wait at least 5 clock cycles
SysCtlDelay(2);
//Set PE4 as SCL
GPIOPinTypeI2CSCL(GPIO_PORTE_BASE, GPIO_PIN_4);
//Set PE5 as SDA
GPIOPinTypeI2C(GPIO_PORTE_BASE, GPIO_PIN_5);
//Configure Master,
I2CMasterInitExpClk(I2C2_BASE, SysCtlClockGet(), false);
}
uint32_t i2c_read() {
I2CMasterSlaveAddrSet(I2C2_BASE, SLAVE_ADDRESS, false);
I2CMasterDataPut(I2C2_BASE, 0x1A);
I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(I2CMasterBusBusy(I2C2_BASE)); //Loop until the bus is no longer busy
I2CMasterSlaveAddrSet(I2C2_BASE, SLAVE_ADDRESS, true );
I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
while(I2CMasterBusBusy(I2C2_BASE)); //Loop until the bus is no longer busy
first_byte = I2CMasterDataGet(I2C2_BASE);
return first_byte;
}
void setup()
{
Serial.begin(9600);
i2c_setup();
}
void loop()
{
int test = i2c_read();
Serial.println(test);
delay(1000);
}
I'm using Energia to test my program, and when I try to read from the specified register, I get the same result, no matter which register I choose, the result is always decimal 229 (this is the Accelerometer's Device Address).
Can somebody point me in the right direction, I've been looking at my code for quite some time and still don't know whats wrong...
Thanks!
I skimmed through your code and everything seems Okay. Clearly something is working right if you get a response. But Like Martin said , figuring the problem without being there is somewhat difficult. Instead of Writing 0x1A can you try using one of the other I2C commands for the accelerametor ? Also if the jumper is connected to VDD your address should be 0x69 (105 decimal) are you sure it's 0x68 ?
I looked up the documentation on sparkfuns website and they provided the following list
of commands.
char WHO_AM_I = 0x00;
char SMPLRT_DIV= 0x15;
char DLPF_FS = 0x16;
char GYRO_XOUT_H = 0x1D;
char GYRO_XOUT_L = 0x1E;
char GYRO_YOUT_H = 0x1F;
char GYRO_YOUT_L = 0x20;
char GYRO_ZOUT_H = 0x21;
char GYRO_ZOUT_L = 0x22;
GL hope everything works out. Been meaning to buy my own to play around with so keep me posted !

Resources