J16 LPC1769 SPI -TTP229

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 …

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

 

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!!!

You can directly use the MIOS32_BOARD_J5 or MIOS32_BOARD_J10 functions as digital I/O
http://www.ucapps.de/mios32_c.htmltutorial #4 and #5
[List of MIOS32_BOARD functions](http://www.midibox.org/mios32/manual/group m_i_o_s32 b_o_a_r_d.html)

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

I’m going to study and then try.

 

Tks!!

 

I think this can help too.
See intouch() and getbit() functions, this is the mechanism I was talking about.

Best regards
 

Very interesting!! I’ll study it calmly.

 

Again, thank you !!

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; &nbsp;// The pin number of the clock pin. const int SDO\_PIN = 2; &nbsp;// The pin number of the data pin. char \_key16; char i=0; char key; char keypress; /////////TTP229 Functions//////////////////////////// void TTP229(char sclPin, char sdoPin) { &nbsp; &nbsp;MIOS32\_BOARD\_J28\_PinInit(sclPin,MIOS32\_BOARD\_PIN\_MODE\_OUTPUT\_PP); &nbsp; &nbsp;MIOS32\_BOARD\_J28\_PinInit(sdoPin,MIOS32\_BOARD\_PIN\_MODE\_INPUT\_PD); &nbsp; &nbsp;MIOS32\_BOARD\_J28\_PinSet(sclPin,1); } bool GetBit() { &nbsp;&nbsp; &nbsp;MIOS32\_BOARD\_J28\_PinSet(1,0); &nbsp;&nbsp; &nbsp;MIOS32\_DELAY\_Wait\_uS(2); &nbsp;&nbsp; &nbsp;bool retVal = !MIOS32\_BOARD\_J28\_PinGet(2); &nbsp;&nbsp; &nbsp;MIOS32\_BOARD\_J28\_PinSet(1,1); &nbsp;&nbsp; &nbsp;MIOS32\_DELAY\_Wait\_uS(2); &nbsp;&nbsp; &nbsp;return retVal; } bool IsTouch() { &nbsp;&nbsp; &nbsp;unsigned timeout = 6000; // 50ms timeout &nbsp;&nbsp; &nbsp;while (MIOS32\_BOARD\_J28\_PinGet(2)) // DV LOW &nbsp;&nbsp; &nbsp;{ &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (timeout-1 == 0) return false; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;MIOS32\_DELAY\_Wait\_uS(10); &nbsp;&nbsp; &nbsp;} &nbsp;&nbsp; &nbsp;while (!MIOS32\_BOARD\_J28\_PinGet(2)) // DV HIGH &nbsp;&nbsp; &nbsp;{ &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (timeout-1 == 0) return false; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;MIOS32\_DELAY\_Wait\_uS(10); &nbsp;&nbsp; &nbsp;} &nbsp;&nbsp; &nbsp;MIOS32\_DELAY\_Wait\_uS(10); // Tw &nbsp;&nbsp; &nbsp;return true; } char GetKey16() { &nbsp;&nbsp; &nbsp;if (IsTouch()) Key16(); &nbsp;&nbsp; &nbsp;return \_key16; } void Key16() { &nbsp;&nbsp; &nbsp;\_key16 = 0; &nbsp;&nbsp; &nbsp;for (i = 0; i \< 16; i++) &nbsp;&nbsp; &nbsp;if (GetBit())\_key16 = i + 1;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;MIOS32\_DELAY\_Wait\_uS(2000); // Tout } void APP\_Init(void) { &nbsp; &nbsp;MIOS32\_DELAY\_Init(0);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;MIOS32\_SPI\_Init(0); &nbsp; &nbsp;MIOS32\_SPI\_IO\_Init(0,MIOS32\_SPI\_PIN\_DRIVER\_STRONG); &nbsp; &nbsp;MIOS32\_SPI\_TransferModeInit(0,MIOS32\_SPI\_MODE\_CLK1\_PHASE1,MIOS32\_SPI\_PRESCALER\_8); &nbsp; &nbsp;MIOS32\_BOARD\_Init(0); &nbsp; &nbsp;//MIOS32\_BOARD\_J28\_PinInit(0,MIOS32\_BOARD\_PIN\_MODE\_OUTPUT\_PP); &nbsp; &nbsp;MIOS32\_BOARD\_J28\_PinInit(1,MIOS32\_BOARD\_PIN\_MODE\_OUTPUT\_PP); &nbsp; &nbsp;MIOS32\_BOARD\_J28\_PinInit(2,MIOS32\_BOARD\_PIN\_MODE\_INPUT\_PD); &nbsp; // MIOS32\_BOARD\_J28\_PinInit(3,MIOS32\_BOARD\_PIN\_MODE\_OUTPUT\_PP);&nbsp; &nbsp; &nbsp;TTP229(SCL\_PIN, SDO\_PIN); &nbsp; } void APP\_Tick(void) { &nbsp;&nbsp; &nbsp; key = GetKey16(); if(key) { keypress=key;&nbsp;&nbsp; &nbsp; MIOS32\_MIDI\_SendNoteOn(DEFAULT, Chn4, keypress, 127); } if(key==0 ) &nbsp; { &nbsp;&nbsp; &nbsp; MIOS32\_MIDI\_SendNoteOn(DEFAULT, Chn4, keypress, 0); &nbsp;}&nbsp;&nbsp; &nbsp; } /////////// 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 !!!

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” :wink:
Best

Bruno

Quote

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” :wink:
Best

Bruno

Great stuff Marco. Thanks for sharing your work with the community by the way.