Jump to content

J16 LPC1769 SPI -TTP229


Dj Marco BH
 Share

Recommended Posts

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

SO to SI.jpg

Edited by Dj Marco BH
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by Dj Marco BH
Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...