thanks to Zoltan Hudak publish the way to use stm32f103c8t6 on mbed. now you can use it with MPC4725 DAC

Dependencies:   mbed-STM32F103C8T6 mbed

Fork of Wii_IRCam_Test by Michael Shimniok

Committer:
Zeran
Date:
Tue May 23 16:52:22 2017 +0000
Revision:
2:2b68d1d14aca
Parent:
1:150525e9c21f
Child:
3:37fb1e2aacf3
stm32f103c8t6 MPC4725 DAC

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Zeran 2:2b68d1d14aca 1 #include "stm32f103c8t6.h"
shimniok 0:cf1bc7c313b4 2 #include "mbed.h"
Zeran 2:2b68d1d14aca 3 #include "mcp4725.h"
shimniok 0:cf1bc7c313b4 4
shimniok 0:cf1bc7c313b4 5 // Adapted from kako's source code: http://www.kako.com/neta/2008-009/2008-009.html
shimniok 0:cf1bc7c313b4 6 // i2c protocol details from - http://blog.makezine.com/archive/2008/11/hacking_the_wiimote_ir_ca.html
shimniok 0:cf1bc7c313b4 7 // wiring from - http://translate.google.com/translate?u=http://www.kako.com/neta/2007-001/2007-001.html&hl=en&ie=UTF-8&sl=ja&tl=en
shimniok 0:cf1bc7c313b4 8 // obviously mbed is 3.3v so no level translation is needed
shimniok 0:cf1bc7c313b4 9 // using built in i2c on pins 9/10
shimniok 0:cf1bc7c313b4 10 //
shimniok 1:150525e9c21f 11 // PC GUI client here: http://code.google.com/p/wii-cam-blobtrack/
shimniok 1:150525e9c21f 12 //
shimniok 1:150525e9c21f 13 // Interfacing details here: http://www.bot-thoughts.com/2010/12/connecting-mbed-to-wiimote-ir-camera.html
shimniok 1:150525e9c21f 14 //
shimniok 0:cf1bc7c313b4 15
Zeran 2:2b68d1d14aca 16 MCP4725 mcp4725_interface(PB_9, PB_8, MCP4725::Standard100kHz, 0);//sda,scl,bus_frequency,device_address_bit
Zeran 2:2b68d1d14aca 17 // modes : Standard100kHz Fast400kHz HighSpeed3_4Mhz
Zeran 2:2b68d1d14aca 18 DigitalOut F_R(PC_14);
Zeran 2:2b68d1d14aca 19 //PwmOut servo(PA_0);
shimniok 0:cf1bc7c313b4 20
Zeran 2:2b68d1d14aca 21 //I2C i2c(PB_7, PB_6); // sda, scl
Zeran 2:2b68d1d14aca 22 //I2C i2c(PB_9, PB_8); // sda, scl
Zeran 2:2b68d1d14aca 23 //const int addr = 0xB0; // define the I2C Address of camera
Zeran 2:2b68d1d14aca 24 //int c = 0;
shimniok 0:cf1bc7c313b4 25
Zeran 2:2b68d1d14aca 26
Zeran 2:2b68d1d14aca 27
Zeran 2:2b68d1d14aca 28
Zeran 2:2b68d1d14aca 29 int main()
shimniok 0:cf1bc7c313b4 30 {
Zeran 2:2b68d1d14aca 31 Serial pc(PA_2, PA_3);
Zeran 2:2b68d1d14aca 32 confSysClock();
Zeran 2:2b68d1d14aca 33 // PC serial output
shimniok 0:cf1bc7c313b4 34 pc.baud(115200);
shimniok 1:150525e9c21f 35 //pc.printf("Initializing camera...");
Zeran 2:2b68d1d14aca 36 int dac_value = (int) (0xFFF * (0/3.3) );
Zeran 2:2b68d1d14aca 37 mcp4725_interface.write(MCP4725::Normal, dac_value, false);
Zeran 2:2b68d1d14aca 38 //modes: Normal PowerDown1k PowerDown100k PowerDown500k
shimniok 0:cf1bc7c313b4 39
shimniok 0:cf1bc7c313b4 40 // read I2C stuff
shimniok 0:cf1bc7c313b4 41 while(1) {
Zeran 2:2b68d1d14aca 42 if(pc.readable()) {
Zeran 2:2b68d1d14aca 43 char c = pc.getc();//-128;
Zeran 2:2b68d1d14aca 44 //c = c*3;
Zeran 2:2b68d1d14aca 45 //pc.putc(c);
Zeran 2:2b68d1d14aca 46
Zeran 2:2b68d1d14aca 47 if (c>=0x80) {
Zeran 2:2b68d1d14aca 48 F_R = 1;
Zeran 2:2b68d1d14aca 49 c = c - 127;
Zeran 2:2b68d1d14aca 50 //pc.putc(c);
Zeran 2:2b68d1d14aca 51 mcp4725_interface.write(MCP4725::Normal,uint16_t(c*20),false);
Zeran 2:2b68d1d14aca 52 } else {
Zeran 2:2b68d1d14aca 53 F_R = 0;
Zeran 2:2b68d1d14aca 54 c = 127 - c;
Zeran 2:2b68d1d14aca 55 //pc.putc(c);
Zeran 2:2b68d1d14aca 56 mcp4725_interface.write(MCP4725::Normal,uint16_t(c*20),false);
Zeran 2:2b68d1d14aca 57 }
Zeran 2:2b68d1d14aca 58 }
Zeran 2:2b68d1d14aca 59 /*for(int i = 0; i<0xFFF; i++){
Zeran 2:2b68d1d14aca 60 mcp4725_interface.write(MCP4725::Normal, i, false);
Zeran 2:2b68d1d14aca 61 wait(0.01);
Zeran 2:2b68d1d14aca 62 }*/
shimniok 0:cf1bc7c313b4 63 }
shimniok 0:cf1bc7c313b4 64
shimniok 0:cf1bc7c313b4 65 }