Other Parts Discussed in Thread: HALCOGEN
Tool/software:
#include "sys_common.h"
/* USER CODE BEGIN (1) */
#include "i2c.h"
#include "gio.h"
#include <stdio.h>
/* USER CODE END */
/** @fn void main(void)
* @brief Application main function
* @note This function is empty by default.
*
* This function is called after startup.
* The user can use this function to implement the application.
*/
/* USER CODE BEGIN (2) */
#define DATA_COUNT 10
#define Master_Address 0x26
#define Slave_Address 0x8
uint8_t TX_Data_Master[10] = { 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19};
uint8_t RX_Data_Master[10] = { 0 };
/* USER CODE END */
int main(void)
{
/* USER CODE BEGIN (3) */
_enable_IRQ();
i2cInit();
gioInit();
int repeat = 0;
int delay = 0;
int i = 0;
gioSetDirection(gioPORTB, 0xFF);
i2cSetSlaveAdd(i2cREG1, Slave_Address);
i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
i2cEnableNotification(i2cREG1, I2C_TX_INT);
for (repeat = 0; repeat < 2; repeat++) {
i2cSetCount(i2cREG1, DATA_COUNT);
i2cSetMode(i2cREG1, I2C_MASTER);
i2cSetStop(i2cREG1);
i2cSetStart(i2cREG1);
i2cSend(i2cREG1, DATA_COUNT, TX_Data_Master);
while(i2cIsBusBusy(i2cREG1) == true);
while(i2cIsStopDetected(i2cREG1) == 0);
i2cClearSCD(i2cREG1);
for(delay=0;delay<1000000;delay++);
}
while(1);
/* USER CODE END */
return 0;
}
/* USER CODE BEGIN (4) */
void i2cNotification(i2cBASE_t *i2c, uint32 flags) {
if (flags & I2C_TX_INT) {
printf("I2C ile TX_Data_Master dizisinde ki veriler başarıyla gönderildi.");
}
}
/* USER CODE END */
I'm using two boards for communication via I2C. I am using the following code to send the values in the TX_Data_Master[10] array to the second board. Below, I will add the code for the second board. In this code, the values from the TX_Data_Master[10] array will be saved to the RX_Data_Slave[10] array. When I send the codes to the boards and run the above code step by step, the program gets stuck at the "while(i2cIsStopDetected(i2cREG1) == 0);" part and doesn't progress. Additionally, the "i2cNotification()" interrupt does not trigger when the "i2cSend()" function is executed. WHAT SHOULD I DO? (I HAVE ALSO ATTACHED THE NECESSARY CODES FOR THE SECOND BOARD BELOW.) .
#include "sys_common.h"
/* USER CODE BEGIN (1) */
#include "i2c.h"
#include "gio.h"
#include <stdio.h>
/* USER CODE END */
/** @fn void main(void)
* @brief Application main function
* @note This function is empty by default.
*
* This function is called after startup.
* The user can use this function to implement the application.
*/
/* USER CODE BEGIN (2) */
#define DATA_COUNT 10
#define Slave_Address 0x8
uint8_t RX_Data_Slave[10] = { 0 };
int i = 0;
/* USER CODE END */
int main(void)
{
/* USER CODE BEGIN (3) */
_enable_IRQ();
i2cInit();
gioInit();
int repeat = 0;
int delay = 0;
gioSetDirection(gioPORTB, 0xFF);
i2cSetSlaveAdd(i2cREG1, Slave_Address);
i2cSetDirection(i2cREG1, I2C_RECEIVER);
i2cEnableNotification(i2cREG1, I2C_RX_INT);
for (repeat = 0; repeat < 2; ++repeat) {
i2cSetCount(i2cREG1, DATA_COUNT);
i2cSetMode(i2cREG1, I2C_SLAVE);
i2cSetStop(i2cREG1);
i2cSetStart(i2cREG1);
i2cReceive(i2cREG1, DATA_COUNT, RX_Data_Slave);
while(i2cIsBusBusy(i2cREG1) == true);
while(i2cIsStopDetected(i2cREG1) == 0);
i2cClearSCD(i2cREG1);
for (delay = 0; delay < 1000000; delay++);
}
while(1);
/* USER CODE END */
return 0;
}
/* USER CODE BEGIN (4) */
void i2cNotification(i2cBASE_t *i2c, uint32 flags) {
if (flags & I2C_RX_INT) {
printf("I2C ile RX_Data_Slave dizisine değerler başarıyla kaydedildi.");
for (i = 0; i < DATA_COUNT; i++) {
if (RX_Data_Slave[i] != 0) {
gioSetBit(gioPORTB, 1, 1);
}
}
}
}
/* USER CODE END */