Dj Marco BH Posted September 25, 2017 Report Share Posted September 25, 2017 (edited) Hi all, I will not use the SDcard. I will use a capacitive touch sensor TTP229 at 2 wires(16 keys). http://www.tontek.com.tw/download.asp?sn=726 I was able to use the sensor on the J16. using the "SI" and "SC" pin. How to configure the J16 pins for two "SI" inputs?Or how to configure II2C and I2S for SI and SC? I want to use at least two TTP229 Below the code for J16 PIN SI. mios32_config.h #define MIOS32_SPI0_IN_INIT { MIOS32_SYS_LPC_PINMODE(1, 24, 2); \ MIOS32_SYS_LPC_PINMODE(1, 23, 0); \ MIOS32_SYS_LPC_PINMODE(1, 22, 2); \ MIOS32_SYS_LPC_PINMODE(1, 21, 2); \ MIOS32_SYS_LPC_PINMODE(1, 20, 2); } APP.C u8 receive; u8 receive1; u8 flag1=0; u8 flag2=0; char valor1; char valor2; void APP_Init(void) { // initialize all LEDs MIOS32_BOARD_LED_Init(0xffffffff); MIOS32_SPI_Init(0); MIOS32_SPI_IO_Init(0,MIOS32_SPI_PIN_DRIVER_STRONG); MIOS32_SPI_TransferModeInit(0,MIOS32_SPI_MODE_CLK1_PHASE1,MIOS32_SPI_PRESCALER_8); } void APP_Tick(void) { receive=MIOS32_SPI_TransferByte(0,receive); /////valor 255 if not pressed receive1=MIOS32_SPI_TransferByte(0,receive1);////valor 255 if not pressed if(receive<255 && flag1==0)//////if pressed { valor1=receive-127; MIOS32_MIDI_SendNoteOn(DEFAULT, Chn4, valor1, 127); flag1=1; // MIOS32_MIDI_SendDebugMessage("Recebido:%u FLAG1:%u\n",valor1, flag1); } if(receive==255 && flag1==1 ) { MIOS32_MIDI_SendNoteOff(DEFAULT, Chn4, valor1, 0); flag1=0; } if(receive1<255 && flag2==0)//////if pressed { valor2=receive1-127; MIOS32_MIDI_SendNoteOn(DEFAULT, Chn5, valor2, 127); flag2=1; } if(receive1==255 && flag2==1) { MIOS32_MIDI_SendNoteOff(DEFAULT, Chn5, valor2, 0); flag2=0; } } Video Test in Portuguese ... Edited September 25, 2017 by Dj Marco BH Quote Link to comment Share on other sites More sharing options...
Antichambre Posted September 25, 2017 Report Share Posted September 25, 2017 Hi Marco, J16 is a SPI port and you use its routine but... Your peripheral seems to communicate by an I2C bus. Its data line is a bidirectional one and there's no Chip Select, then better to use J4A for your first TT229 and J4B for the second. Or you can create your own driver by using any GPIO... Best Quote Link to comment Share on other sites More sharing options...
Dj Marco BH Posted September 25, 2017 Author Report Share Posted September 25, 2017 Tks!!! Exactly, it does not have CS. I think it's not an I2C because it has no address. It communicates using 16 clock pulses, each pulse reads a key, seems to be a proprietary protocol similar to SPI without CS. Where can I find information on how to control any LPC pin? For example: the I2C pins. Tks!!! Quote Link to comment Share on other sites More sharing options...
Antichambre Posted September 25, 2017 Report Share Posted September 25, 2017 You can directly use the MIOS32_BOARD_J5 or MIOS32_BOARD_J10 functions as digital I/Ohttp://www.ucapps.de/mios32_c.html tutorial #4 and #5List of MIOS32_BOARD functions You can emulate your 16 clocks at the requested speed on an Output pin and get the state of 2 others Input pins on each clock transition you make. best Quote Link to comment Share on other sites More sharing options...
Dj Marco BH Posted September 25, 2017 Author Report Share Posted September 25, 2017 I'm going to study and then try. Tks!! Quote Link to comment Share on other sites More sharing options...
Antichambre Posted September 25, 2017 Report Share Posted September 25, 2017 I think this can help too. See intouch() and getbit() functions, this is the mechanism I was talking about. Best regards Quote Link to comment Share on other sites More sharing options...
Dj Marco BH Posted September 25, 2017 Author Report Share Posted September 25, 2017 Very interesting!! I'll study it calmly. Again, thank you !! Quote Link to comment Share on other sites More sharing options...
Dj Marco BH Posted September 28, 2017 Author Report Share Posted September 28, 2017 (edited) On 25/09/2017 at 8:11 PM, Antichambre said: I think this can help too. See intouch() and getbit() functions, this is the mechanism I was talking about. Best regards I was able to adapt the code, it's a bit messy but it works. I used J28 Board !!! And you can still use one more TTP229 !! Some things in the code are being repeated, then I will improve the code. /////////////////////////////////////////////////////////// #include <mios32.h> #include "app.h" //#include "TTP229.h" // include everything FreeRTOS related we don't understand yet ;) #include <FreeRTOS.h> #include <portmacro.h> #include <task.h> #include <queue.h> #include <semphr.h> #include <stdbool.h> /////////TTP229//////////////////////////// char sclPin; char sdoPin; const int SCL_PIN = 1; // The pin number of the clock pin. const int SDO_PIN = 2; // The pin number of the data pin. char _key16; char i=0; char key; char keypress; /////////TTP229 Functions//////////////////////////// void TTP229(char sclPin, char sdoPin) { MIOS32_BOARD_J28_PinInit(sclPin,MIOS32_BOARD_PIN_MODE_OUTPUT_PP); MIOS32_BOARD_J28_PinInit(sdoPin,MIOS32_BOARD_PIN_MODE_INPUT_PD); MIOS32_BOARD_J28_PinSet(sclPin,1); } bool GetBit() { MIOS32_BOARD_J28_PinSet(1,0); MIOS32_DELAY_Wait_uS(2); bool retVal = !MIOS32_BOARD_J28_PinGet(2); MIOS32_BOARD_J28_PinSet(1,1); MIOS32_DELAY_Wait_uS(2); return retVal; } bool IsTouch() { unsigned timeout = 6000; // 50ms timeout while (MIOS32_BOARD_J28_PinGet(2)) // DV LOW { if (timeout-1 == 0) return false; MIOS32_DELAY_Wait_uS(10); } while (!MIOS32_BOARD_J28_PinGet(2)) // DV HIGH { if (timeout-1 == 0) return false; MIOS32_DELAY_Wait_uS(10); } MIOS32_DELAY_Wait_uS(10); // Tw return true; } char GetKey16() { if (IsTouch()) Key16(); return _key16; } void Key16() { _key16 = 0; for (i = 0; i < 16; i++) if (GetBit())_key16 = i + 1; MIOS32_DELAY_Wait_uS(2000); // Tout } void APP_Init(void) { MIOS32_DELAY_Init(0); MIOS32_SPI_Init(0); MIOS32_SPI_IO_Init(0,MIOS32_SPI_PIN_DRIVER_STRONG); MIOS32_SPI_TransferModeInit(0,MIOS32_SPI_MODE_CLK1_PHASE1,MIOS32_SPI_PRESCALER_8); MIOS32_BOARD_Init(0); //MIOS32_BOARD_J28_PinInit(0,MIOS32_BOARD_PIN_MODE_OUTPUT_PP); MIOS32_BOARD_J28_PinInit(1,MIOS32_BOARD_PIN_MODE_OUTPUT_PP); MIOS32_BOARD_J28_PinInit(2,MIOS32_BOARD_PIN_MODE_INPUT_PD); // MIOS32_BOARD_J28_PinInit(3,MIOS32_BOARD_PIN_MODE_OUTPUT_PP); TTP229(SCL_PIN, SDO_PIN); } void APP_Tick(void) { key = GetKey16(); if(key) { keypress=key; MIOS32_MIDI_SendNoteOn(DEFAULT, Chn4, keypress, 127); } if(key==0 ) { MIOS32_MIDI_SendNoteOn(DEFAULT, Chn4, keypress, 0); } } /////////// in app.h add lines////////////////////////////// extern void APP_AIN_NotifyChange(u32 pin, u32 pin_value); extern void Key16(void); extern void TTP229(char sclPin, char sdoPin); TKS TKS TKS !!!!! Edited September 28, 2017 by Dj Marco BH Quote Link to comment Share on other sites More sharing options...
Antichambre Posted September 28, 2017 Report Share Posted September 28, 2017 You're welcome! Happy that it helped you. Always check if there's source code somewhere on the internet, I just google "TTP229 source C" ;) Best Bruno Quote Link to comment Share on other sites More sharing options...
Cortinas Posted October 12, 2017 Report Share Posted October 12, 2017 (edited) Quote You're welcome! Happy that it helped you. Always check this excellent Quick Extender Pro site and if there's source code somewhere on the internet, I just google "TTP229 source C" ;) Best Bruno Great stuff Marco. Thanks for sharing your work with the community by the way. Edited October 29, 2021 by Cortinas Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.