3174 views|0 replies

12

Posts

0

Resources
The OP
 

TMS570LS1224_GY30 light sensor driver [Copy link]

  • 1. Check the data sheet:

1. Sending mode: Send slave address: 0x23, send instruction 0x10; end;

Wait 180ms for data collection;

2. Receiving mode: Send slave address: 0x23, wait for high byte data from slave, send response signal after receiving data, wait for low byte data from slave, send non-response signal after receiving data, and end;

It should be noted that in TMS570, only the slave address needs to be filled in i2cSetSlaveAdd(). The first byte sent after i2cSetStart(i2cREG1) is the slave address, which is filled with '0' in transmit mode and '1' in receive mode.

  • 2. Set up MCU

I2C Global:

Need to pay attention to pin multiplexing;

  • 3. Code
#include "sys_common.h"

/* USER CODE BEGIN (1) */
#include "i2c.h"
#include "rti.h"
#include "het.h"
#include "pinmux.h"
/* USER CODE END */


/* USER CODE BEGIN (2) */


uint8 is_stop = 0;


/* USER CODE END */

int main(void)
{
/* USER CODE BEGIN (3) */
    i2cInit();
    rtiInit();
    hetInit();
    muxInit();

    _enable_IRQ();

    uint8 high_Byte =0,low_Byte = 0;

    i2cSetSlaveAdd(i2cREG1, 0x23 );

    i2cSetDirection(i2cREG1, I2C_TRANSMITTER);

    i2cSetMode(i2cREG1, I2C_MASTER);

    i2cSetStop(i2cREG1);

    i2cSetStart(i2cREG1);

    i2cSendByte(i2cREG1, 0x10);


    i2cSetStop(i2cREG1);


    while(i2cIsBusBusy(i2cREG1) == true);

    while(i2cIsStopDetected(i2cREG1) == 0);

            /* Clear the Stop condition */
    i2cClearSCD(i2cREG1);

   // pinmuxGetConfigValue(REVISION_REG,CurrentValue);

    rtiREG1->CMP[0U].COMPx = 1800000U;
    rtiREG1->CMP[0U].UDCPx = 1800000U;

    rtiEnableNotification(rtiNOTIFICATION_COMPARE0);
    rtiStartCounter(rtiCOUNTER_BLOCK0);

    while(is_stop);

    rtiStopCounter(rtiCOUNTER_BLOCK0);

    i2cSetSlaveAdd(i2cREG1, 0x23);

    i2cSetDirection(i2cREG1, I2C_RECEIVER);

    i2cSetMode(i2cREG1, I2C_MASTER);

    i2cSetStart(i2cREG1);



    high_Byte = i2cReceiveByte(i2cREG1);

    i2cREG1->STR |=1<<13;

    low_Byte = i2cReceiveByte(i2cREG1);

    i2cSetStop(i2cREG1);

    asm(" nop");
    asm(" nop");
    asm(" nop");

    while(1);

/* USER CODE END */

    return 0;
}


/* USER CODE BEGIN (4) */

void rtiNotification(uint32 notification)
{
    is_stop = 1;
}
/* USER CODE END */

Here I use RTI timing method for delay;

  • 4. Result graph

BH1750FVI.pdf

386.29 KB, downloads: 6

This post is from Embedded System

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list