You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FT6236触摸屏坐标获取问题求助(基于STM32F3开发板)

Hey there! Let's work through this FT6236 touch coordinate issue on your STM32F3 using the standard peripheral library. The core problem here is that your current code only checks for gesture events but doesn't actually read the raw touch coordinate registers from the FT6236, which is how you get accurate X/Y positions.

First, Let's Recap FT6236's Key Registers for Touch Data

The FT6236 stores touch information in a set of contiguous registers starting at 0x00:

  • 0x00: Touch status (low 4 bits = number of active touch points)
  • 0x01: Gesture ID (for swipe/move events)
  • 0x02: First touch point X coordinate (low 8 bits)
  • 0x03: First touch point X coordinate (high 4 bits, bits 0-3 only)
  • 0x04: First touch point Y coordinate (low 8 bits)
  • 0x05: First touch point Y coordinate (high 4 bits, bits 0-3 only)

Step 1: Verify I2C Communication First

Before worrying about coordinates, confirm your STM32 can talk to the FT6236. The chip's 7-bit I2C address is 0x38, so you can read the device ID register (0xA8) to validate:

uint8_t ft6236_id;
FT6236_ReadReg(0xA8, &ft6236_id, 1);
// Should return 0x11 or 0x63 (depends on FT6236 variant)
if(ft6236_id != 0x11 && ft6236_id != 0x63) {
    // I2C communication is broken—check wiring/pins/config
}

Step 2: Write a Helper to Read FT6236 Registers

Here's a standard peripheral library-compatible function to read multiple registers over I2C (adjust I2C port/pins to match your setup):

uint8_t FT6236_ReadReg(uint8_t reg_addr, uint8_t *data_buf, uint8_t len) {
    // Send I2C start condition
    I2C_GenerateSTART(I2C1, ENABLE);
    while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));

    // Send device write address (0x38 << 1 | 0)
    I2C_Send7bitAddress(I2C1, 0x70, I2C_Direction_Transmitter);
    while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));

    // Send target register address
    I2C_SendData(I2C1, reg_addr);
    while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));

    // Repeat start for read
    I2C_GenerateSTART(I2C1, ENABLE);
    while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));

    // Send device read address (0x38 << 1 | 1)
    I2C_Send7bitAddress(I2C1, 0x71, I2C_Direction_Receiver);
    while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));

    // Read data bytes
    for(uint8_t i = 0; i < len; i++) {
        if(i == len - 1) {
            // No ACK for final byte, send stop
            I2C_AcknowledgeConfig(I2C1, DISABLE);
            I2C_GenerateSTOP(I2C1, ENABLE);
        }
        while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED));
        data_buf[i] = I2C_ReceiveData(I2C1);
    }

    // Restore ACK for future reads
    I2C_AcknowledgeConfig(I2C1, ENABLE);
    return 0;
}

Step 3: Read and Process Touch Coordinates

Now, let's build a function to fetch touch points, combine the raw 12-bit coordinates, and map them to your TFTM032 screen (assuming 320x240 resolution):

typedef struct {
    uint8_t touch_count;
    uint16_t screen_x;
    uint16_t screen_y;
    uint8_t gesture_id;
} FT6236_TouchInfo;

FT6236_TouchInfo FT6236_GetTouchData(void) {
    FT6236_TouchInfo info = {0};
    uint8_t raw_data[6]; // Read registers 0x00 to 0x05

    FT6236_ReadReg(0x00, raw_data, 6);
    info.touch_count = raw_data[0] & 0x0F; // Extract touch count (low 4 bits)
    info.gesture_id = raw_data[1];

    if(info.touch_count > 0) {
        // Combine 12-bit X/Y coordinates
        uint16_t raw_x = ((raw_data[3] & 0x0F) << 8) | raw_data[2];
        uint16_t raw_y = ((raw_data[5] & 0x0F) << 8) | raw_data[4];

        // Map raw 0-4095 range to TFTM032's 320x240 resolution
        info.screen_x = (raw_x * 320) / 4095;
        info.screen_y = (raw_y * 240) / 4095;

        // Optional: Adjust for screen rotation/flip (uncomment if needed)
        // info.screen_y = 240 - info.screen_y;
        // uint16_t temp = info.screen_x; info.screen_x = info.screen_y; info.screen_y = temp;
    }

    return info;
}

Step 4: Update Your Main Logic

Replace your existing gesture-only code with something that uses the coordinate data:

while(1) {
    FT6236_TouchInfo touch = FT6236_GetTouchData();

    if(touch.touch_count > 0) {
        // Use the mapped screen coordinates here
        printf("Touch detected at X: %d, Y: %d\r\n", touch.screen_x, touch.screen_y);

        // Handle move gesture as you intended
        if(touch.gesture_id & TOUCH_FT6236_GESTURE_MOVE_FLAG) {
            printf("Move gesture active!\r\n");
        }
    }

    Delay_ms(50); // Add small delay to avoid spamming reads
}

Key Troubleshooting Tips

  • I2C Wiring: Double-check SDA/SCL pins are pulled up with 4.7k resistors, and reset pin is properly handled (hold low for 10ms then release on startup).
  • Resolution Mapping: If coordinates are reversed or misaligned, adjust the mapping formula or add axis flip/swap logic.
  • Clock Speed: Ensure your I2C peripheral is configured for 100kHz or 400kHz (FT6236 supports both).

内容的提问来源于stack exchange,提问作者NetworkStudent

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:10:57