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