<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>LPC MicrocontrollersのトピックI2C-bus ROM API - repeated start</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/I2C-bus-ROM-API-repeated-start/m-p/540661#M12092</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by brownm on Wed Oct 15 19:11:49 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi all &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to use the ROM API for the i2C bus in the 11u68, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using the LPCOpen example project "periph_i2c_rom_interrupt" as a basis for my code. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can read and write single bytes (and no doubt multiple bytes - however my device doesn't have these) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to issue a repeated start command to read the next register of the device (MAX9611), I have tried setting the stop_flag in the params struct to false. but that causes the I2C to lockup at the interrupt handler. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas on what the stop_flag actually does - I can't find any documentation on it? &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas on how to issue a repeated start command. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
/* Master transmit/receive in interrupt mode */
static void sendReadI2CMaster(uint16_t AddressI2C, uint8_t *DataInPtr,&amp;nbsp; uint8_t regAddr, uint8_t num_bytes_to_read, bool stop_flag_set){
uint8_t recvData[10], sendData[10];
I2C_PARAM_T param;
I2C_RESULT_T result;
ErrorCode_t error_code;
int sindex = 0, rindex = 0;

/* Setup I2C send for address/send, send desired LED state, then stop */
/* Setup I2C receive for address/read, read desired LED state, then stop */
/* 7-bit address */
sendData[sindex++] = (uint8_t) AddressI2C;
recvData[rindex++] = (uint8_t) AddressI2C | I2C_RD_CMD_BIT;

sendData[sindex++] = (uint8_t) regAddr;

/* Setup parameters for transfer */
param.num_bytes_send = sindex;
param.num_bytes_rec = rindex;
//param.num_bytes_rec = num_bytes_to_read-1;
param.buffer_ptr_send = &amp;amp;sendData[0];
param.buffer_ptr_rec = &amp;amp;recvData[0];
//param.stop_flag = 1;
param.stop_flag = stop_flag_set;
param.func_pt = cbI2CComplete;

/* Do master read transfer */
intErrCode = -1;

/* Function is non-blocking, returned error should be LPC_OK, but isn't checked here */
error_code = LPC_I2CD_API-&amp;gt;i2c_master_tx_rx_intr(i2cHandleMaster, &amp;amp;param, &amp;amp;result);

//BADNESS OCCURS HERE IF stop_flag = false


/* Sleep until transfer is complete, but allow IRQ to wake system
&amp;nbsp;&amp;nbsp; to handle I2C IRQ */
while (intErrCode == -1) {
__WFI();
}

/* Cast saved error code from callback */
error_code = (ErrorCode_t) intErrCode;

/* Completed without errors? */
if (error_code != LPC_OK) {
/* Likely cause is NAK */
DEBUGOUT("i2c_master_tx_rx error code : %x\r\b", error_code);
errorI2C();
}
else {
/* Note results are only valid when there are no errors */
*DataInPtr++ = recvData[0];
*DataInPtr++ = recvData[1];
}
}






&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it hangs here in the handler (but not if stop_flag == true)&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;

void I2C1_IRQHandler(void){
/* Call I2C ISR function in ROM with the I2C handle */
LPC_I2CD_API-&amp;gt;i2c_isr_handler(i2cHandleMaster);
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks and Regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Marshall&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 19:40:45 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T19:40:45Z</dc:date>
    <item>
      <title>I2C-bus ROM API - repeated start</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/I2C-bus-ROM-API-repeated-start/m-p/540661#M12092</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by brownm on Wed Oct 15 19:11:49 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi all &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to use the ROM API for the i2C bus in the 11u68, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using the LPCOpen example project "periph_i2c_rom_interrupt" as a basis for my code. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can read and write single bytes (and no doubt multiple bytes - however my device doesn't have these) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to issue a repeated start command to read the next register of the device (MAX9611), I have tried setting the stop_flag in the params struct to false. but that causes the I2C to lockup at the interrupt handler. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas on what the stop_flag actually does - I can't find any documentation on it? &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas on how to issue a repeated start command. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
/* Master transmit/receive in interrupt mode */
static void sendReadI2CMaster(uint16_t AddressI2C, uint8_t *DataInPtr,&amp;nbsp; uint8_t regAddr, uint8_t num_bytes_to_read, bool stop_flag_set){
uint8_t recvData[10], sendData[10];
I2C_PARAM_T param;
I2C_RESULT_T result;
ErrorCode_t error_code;
int sindex = 0, rindex = 0;

/* Setup I2C send for address/send, send desired LED state, then stop */
/* Setup I2C receive for address/read, read desired LED state, then stop */
/* 7-bit address */
sendData[sindex++] = (uint8_t) AddressI2C;
recvData[rindex++] = (uint8_t) AddressI2C | I2C_RD_CMD_BIT;

sendData[sindex++] = (uint8_t) regAddr;

/* Setup parameters for transfer */
param.num_bytes_send = sindex;
param.num_bytes_rec = rindex;
//param.num_bytes_rec = num_bytes_to_read-1;
param.buffer_ptr_send = &amp;amp;sendData[0];
param.buffer_ptr_rec = &amp;amp;recvData[0];
//param.stop_flag = 1;
param.stop_flag = stop_flag_set;
param.func_pt = cbI2CComplete;

/* Do master read transfer */
intErrCode = -1;

/* Function is non-blocking, returned error should be LPC_OK, but isn't checked here */
error_code = LPC_I2CD_API-&amp;gt;i2c_master_tx_rx_intr(i2cHandleMaster, &amp;amp;param, &amp;amp;result);

//BADNESS OCCURS HERE IF stop_flag = false


/* Sleep until transfer is complete, but allow IRQ to wake system
&amp;nbsp;&amp;nbsp; to handle I2C IRQ */
while (intErrCode == -1) {
__WFI();
}

/* Cast saved error code from callback */
error_code = (ErrorCode_t) intErrCode;

/* Completed without errors? */
if (error_code != LPC_OK) {
/* Likely cause is NAK */
DEBUGOUT("i2c_master_tx_rx error code : %x\r\b", error_code);
errorI2C();
}
else {
/* Note results are only valid when there are no errors */
*DataInPtr++ = recvData[0];
*DataInPtr++ = recvData[1];
}
}






&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it hangs here in the handler (but not if stop_flag == true)&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;

void I2C1_IRQHandler(void){
/* Call I2C ISR function in ROM with the I2C handle */
LPC_I2CD_API-&amp;gt;i2c_isr_handler(i2cHandleMaster);
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks and Regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Marshall&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:40:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/I2C-bus-ROM-API-repeated-start/m-p/540661#M12092</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:40:45Z</dc:date>
    </item>
  </channel>
</rss>

