Content originally posted in LPCWare by audriusmerfeldas on Sat Jan 09 12:52:24 MST 2016 After debugging I have change me code a little bit, now looks like lpc gets ACK from sensor, but now I am facing problem when I am sendingslave address with read bit after line " LPC_I2C->CONCLR = I2C_I2CONCLR_SIC;" I2C state changes to 0x08 (A START condition has been transmitted), while it should be 0x48 (Slave address + read has been transmitted, NOT ACK has been received.)
Any ideas?
#include "LPC11xx.h" /* LPC11xx definitions */
#include "gpio.h"
#include <cr_section_macros.h>
#include <NXP/crp.h>
// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
#define I2C_I2CONSET_AA ((0x04))
#define I2C_I2CONSET_SI ((0x08))
#define I2C_I2CONSET_STO ((0x10))
#define I2C_I2CONSET_STA ((0x20))
#define I2C_I2CONSET_I2EN ((0x40))
#define I2C_I2CONCLR_AAC ((1<<2))
#define I2C_I2CONCLR_SIC ((1<<3))
#define I2C_I2CONCLR_STOC ((1<<4))
#define I2C_I2CONCLR_STAC ((1<<5))
#define I2C_I2CONCLR_I2ENC ((1<<6))
#define I2C_STAT_CODE_BITMASK ((0xF8))
#define I2C_I2STAT_M_TX_START ((0x08))
#define I2C_I2STAT_M_TX_RESTART ((0x10))
#define I2C_I2STAT_M_TX_SLAW_ACK ((0x18))
#define I2C_I2STAT_M_TX_SLAW_NACK ((0x20))
#define I2C_I2STAT_M_TX_DAT_ACK ((0x28))
#define I2C_I2STAT_M_TX_DAT_NACK ((0x30))
#define I2C_I2STAT_M_TX_ARB_LOST ((0x38))
#define I2C_I2STAT_M_RX_START ((0x08))
#define I2C_I2STAT_M_RX_RESTART ((0x10))
#define I2C_I2STAT_M_RX_SLAR_ACK ((0x40))
#define I2C_I2STAT_M_RX_SLAR_NACK ((0x48))
#define I2C_I2STAT_M_RX_DAT_ACK ((0x50))
#define I2C_I2STAT_M_RX_DAT_NACK ((0x58))
#define I2C_I2DAT_BITMASK ((0xFF))
int delay;
//void I2C_Init( LPC_I2C_TypeDef *I2Cx, uint32_t clockrate );
void I2C_Init(void)
{
LPC_SYSCON->PRESETCTRL |= (1<<1); //De-Asserts Reset Signal to I2C
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<5); //Enable I2C Clock
LPC_IOCON->PIO0_4 &= ~0x3F;
LPC_IOCON->PIO0_4 |= 0x01; //SCL
LPC_IOCON->PIO0_5 &= ~0x3F;
LPC_IOCON->PIO0_5 |= 0x01; //SDA
LPC_I2C->SCLH = 360; //I2PCLK is 72MHz
LPC_I2C->SCLL = 360; //I2PCLK is 72MHz
LPC_I2C->CONCLR = 0xFF; //Clear All Flags
LPC_I2C->CONSET = (1<<6); //I2C Interface Enable
}
uint32_t I2C_Start(void)
{
LPC_I2C->CONCLR = I2C_I2CONCLR_AAC | I2C_I2CONCLR_SIC | I2C_I2CONCLR_STAC;
LPC_I2C->CONSET = I2C_I2CONSET_STA;
while (!(LPC_I2C->CONSET & I2C_I2CONSET_SI));
return (LPC_I2C->STAT & I2C_STAT_CODE_BITMASK);
}
void I2C_Stop(void)
{
LPC_I2C->CONCLR = I2C_I2CONCLR_AAC | I2C_I2CONCLR_SIC | I2C_I2CONCLR_STAC;
LPC_I2C->CONSET = I2C_I2CONSET_STO;
while (LPC_I2C->CONSET & I2C_I2CONSET_STO);
}
uint32_t I2C_Write(unsigned char data)
{
LPC_I2C->DAT = data;
LPC_I2C->CONCLR = I2C_I2CONCLR_SIC;
while (!(LPC_I2C->CONSET & I2C_I2CONSET_SI));
return (LPC_I2C->STAT & I2C_STAT_CODE_BITMASK);
}
unsigned char Slave_Read(void)
{
uint8_t result,res1,res2,res3,res4,res5;
res1=0; res2=0; res3=0; res4=0; res5=0;
if ( I2C_Start() == I2C_I2STAT_M_TX_START )
{
res1=(LPC_I2C->STAT & I2C_STAT_CODE_BITMASK);
LPC_I2C->CONCLR = I2C_I2CONCLR_STAC;
if ( I2C_Write( 0x3A ) == 0x18 ) //device address with write bit
{
res2=(LPC_I2C->STAT & I2C_STAT_CODE_BITMASK);
LPC_I2C->CONCLR = I2C_I2CONCLR_AAC;
LPC_I2C->CONCLR = I2C_I2CONCLR_SIC;
while (!(LPC_I2C->CONSET & I2C_I2CONSET_SI));
}
if ( I2C_Write( 0x0D ) == 0x28 ) //register address
{
res3=(LPC_I2C->STAT & I2C_STAT_CODE_BITMASK);
LPC_I2C->CONCLR = I2C_I2CONCLR_AAC;
LPC_I2C->CONCLR = I2C_I2CONCLR_SIC;
while (!(LPC_I2C->CONSET & I2C_I2CONSET_SI));
}
if ( I2C_Start() == 0x10 ) {
if ( I2C_Write( 0x3B ) == 0x40 ) //SLA+R has been transmitted; ACK has been received
{
LPC_I2C->CONSET = 0x04;//I2C_I2CONCLR_AAC;
LPC_I2C->CONCLR = I2C_I2CONCLR_SIC;
while (!(LPC_I2C->CONSET & I2C_I2CONSET_SI));
result = (uint8_t)(LPC_I2C->DAT & I2C_I2DAT_BITMASK);
I2C_Stop();
return result;
}
// }
}
}
I2C_Stop();
return 0xE8;
}
int main(void)
{
volatile uint8_t result;
//I2C_Init( LPC_I2C, 100000 );
I2C_Init();
while(1)
{
result = Slave_Read();
/* Check result */
for (delay=1000; delay>0 ; delay--)
{
}
}
}
0
件の賞賛
返信
'
var data = div.getElementsByClassName("video-js");
var script = document.createElement('script');
script.src = "https://players.brightcove.net/" + data_account + "/" + data_palyer + "_default/index.min.js";
for(var i=0;i< data.length;i++){
videodata.push(data[i]);
}
}
}
for(var i=0;i< videodata.length;i++){
document.getElementsByClassName('lia-vid-container')[i].innerHTML = videodata[i].outerHTML;
document.body.appendChild(script);
}
}
catch(e){
}
/* Re compile html */
$compile(rootElement.querySelectorAll('div.lia-message-body-content')[0])($scope);
}
if (code_l.toLowerCase() != newBody.getAttribute("slang").toLowerCase()) {
/* Adding Translation flag */
var tr_obj = $filter('filter')($scope.sourceLangList, function (obj_l) {
return obj_l.code.toLowerCase() === newBody.getAttribute("slang").toLowerCase()
});
if (tr_obj.length > 0) {
tr_text = "このコンテンツはlilicon-trans-textからAI支援ツールを使って翻訳されました。".replace(/lilicon-trans-text/g, tr_obj[0].title);
tr_text +='原文を見る';
try {
if ($scope.wootMessages[$rootScope.profLang] != undefined) {
tr_text = $scope.wootMessages[$rootScope.profLang].replace(/lilicon-trans-text/g, tr_obj[0].title);
tr_text +='原文を見る';
}
} catch (e) {
}
} else {
//tr_text = "This message was translated for your convenience!";
tr_text = "lilicon-trans.your.convenience";
}
try {
if (!document.getElementById("tr-msz-" + value)) {
var tr_para = document.createElement("P");
tr_para.setAttribute("id", "tr-msz-" + value);
tr_para.setAttribute("class", "tr-msz");
tr_para.style.textAlign = 'justify';
var tr_fTag = document.createElement("IMG");
tr_fTag.setAttribute("class", "tFlag");
tr_fTag.setAttribute("alt", "翻訳アイコン");
// tr_fTag.setAttribute("title", "翻訳アイコンの免責事項");
tr_fTag.setAttribute("src", "/html/assets/translate-icon.svg");
tr_para.appendChild(tr_fTag);
var container = document.createElement('span');
container.innerHTML = tr_text;
//var tr_textNode = document.createTextNode(container);
tr_para.appendChild(container);
/* Woot message only for multi source */
if(rootElement.querySelector(".lia-message-body-content").previousElementSibling != null && rootElement.querySelector(".lia-message-body-content").previousElementSibling.getAttributeNames().includes("data-generation-timestamp")){
rootElement.querySelector(".lia-message-body-content").previousElementSibling.remove()
}
if(rootElement.querySelector(".lia-quilt-forum-message")){
rootElement.querySelector(".lia-quilt-forum-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-message-view-blog-topic-message")) {
rootElement.querySelector(".lia-message-view-blog-topic-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-blog-reply-message")){
rootElement.querySelector(".lia-quilt-blog-reply-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-tkb-message")){
rootElement.querySelectorAll(".lia-quilt-tkb-message .lia-message-body")[0].insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-tkb-reply-message")){
rootElement.querySelectorAll(".lia-quilt-tkb-reply-message .lia-message-body")[0].insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-idea-message")){
rootElement.querySelector(".lia-quilt-idea-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-idea-reply-message")){
rootElement.querySelector(".lia-quilt-idea-reply-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector('.lia-quilt-occasion-message')){
rootElement.querySelector('.lia-quilt-occasion-message .lia-message-body').insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
}
else {
if (rootElement.querySelectorAll('div.lia-quilt-row-footer').length > 0) {
rootElement.querySelectorAll('div.lia-quilt-row-footer')[0].appendChild(tr_para);
} else {
rootElement.querySelectorAll('div.lia-quilt-column-message-footer')[0].appendChild(tr_para);
}
}
}
} catch (e) {
}
}
} else {
/* Do not display button for same language */
// syncList.remove(value);
var index = $scope.syncList.indexOf(value);
if (index > -1) {
$scope.syncList.splice(index, 1);
}
}
}
}
}
}
/*if(mszList_l.length <= 0){
setTimeout(()=>{
var mszListl = [];
angular.forEach(document.querySelectorAll("[class*='lia-js-data-messageUid']"), function(element) {
var mszId = element.getAttribute("data-lia-message-uid");
if (mszId != null) {
mszListl.push(mszId);
}
});
var mszListid = mszListl;
console.log("mszListl:",mszListl);
},2000)
}else{
var mszListid = mszList_l;
}*/
console.log("mszList_l:",mszList_l.length);
angular.forEach(mszList_l, function (value) {
if (document.querySelectorAll('div.lia-js-data-messageUid-' + value).length > 0) {
var rootElements = document.querySelectorAll('div.lia-js-data-messageUid-' + value);
}else if(document.querySelectorAll('.lia-occasion-message-view .lia-component-occasion-message-view').length >0){
var rootElements = document.querySelectorAll('.lia-occasion-message-view .lia-component-occasion-message-view')[0].querySelectorAll('.lia-occasion-description')[0];
}else {
var rootElements = document.querySelectorAll('div.message-uid-' + value);
}
angular.forEach(rootElements, function (rootElement) {
if (value == '531324' && "ForumTopicPage" == "TkbArticlePage") {
rootElement = document.querySelector('.lia-thread-topic');
}
/* V1.1 Remove from UI */
if (document.getElementById("tr-msz-" + value)) {
document.getElementById("tr-msz-" + value).remove();
}
if (document.getElementById("tr-sync-" + value)) {
document.getElementById("tr-sync-" + value).remove();
}
/* XPath expression for subject and Body */
var lingoRBExp = "//lingo-body[@id = "+"'lingo-body-"+value+"'"+"]";
lingoRSExp = "//lingo-sub[@id = "+"'lingo-sub-"+value+"'"+"]";
/* Get translated subject of the message */
lingoRSXML = doc.evaluate(lingoRSExp, doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for(var i=0;i 0){
angular.forEach(document.querySelectorAll(".PageTitle"), function(subEle) {
subEle.textContent = sub_L;
});
}
}
}
// Label translation
try{
var labelEle = document.querySelector("#labelsForMessage");
if(!labelEle){
labelEle = document.querySelector(".LabelsList");
}
if(labelEle) {
var listContains = labelEle.querySelector('.label');
if (listContains) {
/* Commenting this code as bussiness want to point search with source language label */
// var tagHLink = labelEle.querySelectorAll(".label")[0].querySelector(".label-link").href.split("label-name")[0];
var lingoLabelExp = "//lingo-label/text()";
trLabels = [];
trLabelsHtml = "";
/* Get translated labels of the message */
lingoLXML = doc.evaluate(lingoLabelExp, doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var labelsLength = document.querySelector(".LabelsList").querySelectorAll(".label").length;
var labelSnapshotLength = lingoLXML.snapshotLength;
if (labelsLength == labelSnapshotLength){
for (var k = 0; k < lingoLXML.snapshotLength; k++) {
//trLabels.push(lingoLXML.snapshotItem(i).textContent);
if (k != 0) {
//trLabelsHtml = trLabelsHtml + '