Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test_mc.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2009 Antoine Drouin <poinix@gmail.com>
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
24 // addr 4
25 // J6 = SCL orange
26 // J7 = SDA
27 
28 #include <stm32/flash.h>
29 #include <stm32/misc.h>
30 #include <stm32/i2c.h>
31 
32 #include BOARD_CONFIG
33 #include "mcu.h"
34 #include "mcu_periph/sys_time.h"
35 #include "led.h"
36 
37 static inline void main_init( void );
38 static inline void main_periodic_task( void );
39 static inline void main_event_task( void );
40 
41 static inline void main_i2c_init( void );
42 static inline void main_test_send( void );
43 static void test_gpios(void);
44 
45 int main(void) {
46  main_init();
47 
48  while(1) {
52  }
53 
54  return 0;
55 }
56 
57 
58 static inline void main_init( void ) {
59  mcu_init();
61  main_i2c_init();
62  test_gpios();
63 }
64 
65 static inline void main_periodic_task( void ) {
66 
68  LED_PERIODIC();
69 }
70 
71 static inline void main_event_task( void ) {
72 
73 }
74 
75 
76 static void test_gpios(void) {
77  /* Enable GPIOB clock */
78  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
79  /* Configure I2C1 pins: SCL and SDA ------------------------------------------*/
80  GPIO_InitTypeDef GPIO_InitStructure;
81  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
82  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
83  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
84  GPIO_Init(GPIOC, &GPIO_InitStructure);
85 
86 
87  //GPIOB->BRR = GPIO_Pin_6 | GPIO_Pin_7;
88 
89  GPIOC->BSRR = GPIO_Pin_10 | GPIO_Pin_11;
90 }
91 
92 
93 static inline void main_i2c_init( void ) {
94 
95  /* Enable peripheral clocks --------------------------------------------------*/
96  /* Enable I2C1 clock */
97  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
98  /* Enable GPIOB clock */
99  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
100 
101 
102  /* Configure I2C1 pins: SCL and SDA ------------------------------------------*/
103  GPIO_InitTypeDef GPIO_InitStructure;
104  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
105  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
106  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
107  GPIO_Init(GPIOB, &GPIO_InitStructure);
108 
109 
110  /* I2C configuration ----------------------------------------------------------*/
111  I2C_InitTypeDef I2C_InitStructure;
112  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
113  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
114  I2C_InitStructure.I2C_OwnAddress1 = 0x02;
115  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
116  // I2C_InitStructure.I2C_Ack = I2C_Ack_Disable;
117  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
118  I2C_InitStructure.I2C_ClockSpeed = 200000;
119 
120  /* I2C Peripheral Enable */
121  I2C_Cmd(I2C1, ENABLE);
122  /* Apply I2C configuration after enabling it */
123  I2C_Init(I2C1, &I2C_InitStructure);
124 
125 }
126 
127 static inline void main_test_send( void ) {
128 
129  // return;
130  /* Send START condition */
131  I2C_GenerateSTART(I2C1, ENABLE);
132 
133  /* Test on EV5 and clear it */
134  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
135 
136  //return;
137 
138  /* Send address */
139  // I2C_Send7bitAddress(I2C1, 0x52, I2C_Direction_Transmitter);
140  I2C_Send7bitAddress(I2C1, 0x58, I2C_Direction_Transmitter);
141 
142  // return;
143 
144  /* Test on EV6 and clear it */
145  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
146 
147  // return;
148 
149  /* Snd data */
150  I2C_SendData(I2C1, 0x06);
151 
152  /* Test on EV8 and clear it */
153  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
154 
155  /* Send STOP condition */
156  I2C_GenerateSTOP(I2C1, ENABLE);
157 }
158 
#define I2C1
Definition: LPC21xx.h:166
static void main_test_send(void)
Definition: test_mc.c:127
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
static void main_event_task(void)
Definition: test_mc.c:71
int main(void)
Definition: test_mc.c:45
Architecture independent timing functions.
static void main_init(void)
Definition: test_mc.c:58
static void main_periodic_task(void)
Definition: test_mc.c:65
int sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:35
static bool_t sys_time_check_and_ack_timer(tid_t id)
Definition: sys_time.h:90
#define LED_PERIODIC()
Definition: led_hw.h:8
arch independent mcu ( Micro Controller Unit ) utilities
static void main_i2c_init(void)
Definition: test_mc.c:93
static void test_gpios(void)
Definition: test_mc.c:76
arch independent LED (Light Emitting Diodes) API
void mcu_init(void)
Definition: mcu.c:57