Hello,
I'm trying to configure Renesas s7g2-sk as I2C master and Cypress PSoC as my slave. I'm able to test the slave (with address 0x04) using Bridge control panel and able to read and write properly.
I edited SCI I2C example slave address to 0x04, modified code to only read mode. I'm unable to read the data from the slave.
Please help me if i'm missing something.
When i tested the slave i send in the following format.
Start -> Send a read Command (0x09) -> Read from slave -> stop
My Code:
#include <stdio.h>
#include "sci_i2c_hal_api_mg.h"
#include "sci_i2c_hal_slave_functions_mg.h"
#include "hal_data.h"
/* Comment below #define to disable Semi-hosting (output to Virtual Debug Console) */
#define SEMI_HOSTING
#ifdef SEMI_HOSTING
#ifdef __GNUC__
extern void initialise_monitor_handles(void);
#endif
#endif
#define COMMAND_SIZE (4)
#define COMMAND_BYTE(x) (x)
/***********************************************************************************************************************
* Function Name: master_init
* Description : Function initializes touch controller
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void master_init()
{
/* Initialize i2c master using I2C HAL API */
ssp_err_t err = g_i2c.p_api->open (g_i2c.p_ctrl, g_i2c.p_cfg);
if (SSP_SUCCESS != err)
{
#ifdef SEMI_HOSTING
if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)
{
printf ("SSP_ERROR");
}
#endif
}
}
/***********************************************************************************************************************
End of function master_init
***********************************************************************************************************************/
/***********************************************************************************************************************
* Function Name: master_restart
* Description : Function resets I2C Peripheral and touch controller
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void master_restart()
{
/* Reset touch controller chip (slave) by setting GPIO reset pin low */
//g_ioport.p_api->pinWrite(IOPORT_PORT_06_PIN_09, IOPORT_LEVEL_LOW);
/* Wait for a while keep the reset signal low longer than 1 ms) */
R_BSP_SoftwareDelay (DELAY, BSP_DELAY_UNITS_MILLISECONDS);
/* Resets the I2C peripheral */
ssp_err_t err = g_i2c.p_api->reset (g_i2c.p_ctrl);
if (SSP_SUCCESS != err)
{
#ifdef SEMI_HOSTING
if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)
{
printf ("SSP ERROR=0x%x\n", err);
}
#endif
}
/* Releases touch controller chip (slave) from reset */
//g_ioport.p_api->pinWrite(IOPORT_PORT_06_PIN_09, IOPORT_LEVEL_HIGH);
}
/***********************************************************************************************************************
End of function master_restart
***********************************************************************************************************************/
/***********************************************************************************************************************
* Function Name: master_read
* Description : I2C HAL Read from slave device
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void master_read()
{
uint8_t reg = 0x09;
ssp_err_t err;
/* short delay before starting to write to slave device */
R_BSP_SoftwareDelay (DELAY, BSP_DELAY_UNITS_MILLISECONDS);
#ifdef SEMI_HOSTING
if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)
{
printf ("Read from reg = 0x%x\n", reg);
}
#endif
/* Tell the slave device a register number to read from */
do
{
err = g_i2c.p_api->write (g_i2c.p_ctrl, ®, sizeof(reg), false);
#ifdef SEMI_HOSTING
if (SSP_SUCCESS != err)
{
if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)
{
printf ("SSP ERROR=0x%x\n", err);
}
}
#endif
}
while (SSP_SUCCESS != err);
/* short delay before starting to read from slave device */
R_BSP_SoftwareDelay (DELAY, BSP_DELAY_UNITS_MILLISECONDS);
/* start reading from the slave device */
do
{
err = g_i2c.p_api->read (g_i2c.p_ctrl, ®, (sizeof(reg)) + 1U, false); // unable to read here
#ifdef SEMI_HOSTING
if (SSP_SUCCESS != err)
{
if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)
{
printf ("SSP ERROR=0x%x\n", err);
}
}
#endif
}
while (SSP_SUCCESS != err);
#ifdef SEMI_HOSTING
if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)
{
printf ("Received data = 0x%x\n", reg);
}
#endif
}
/***********************************************************************************************************************
End of function master_read
***********************************************************************************************************************/
/***********************************************************************************************************************
* Function Name: master_run
* Description : Function includes all the methods to operate touch controller
* Arguments : index -
* Where to start looking
* p_output -
* Pointer of where to put the output data
* Return Value : count -
* How many entries were found
***********************************************************************************************************************/
void master_run()
{
#ifdef SEMI_HOSTING
#ifdef __GNUC__
if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)
{
/* Initialize semi hosting */
initialise_monitor_handles ();
}
#endif
#endif
/* Initialize I2C HAL Driver */
master_init ();
/* Reset I2C Master device */
master_restart ();
/* Configure I2C Slave Device (write to slave) */
//master_write ();
}
/***********************************************************************************************************************
End of function master_run
***********************************************************************************************************************/
/***********************************************************************************************************************
* Function Name: sci_i2c_hal_module_guide_project
* Description : Main function demonstrating this module
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void sci_i2c_hal_module_guide_project(void)
{
/* Define the units to be used with the software delay function */
const bsp_delay_units_t bsp_delay_units = BSP_DELAY_UNITS_MILLISECONDS;
/* Set the blink frequency (must be <= bsp_delay_units */
const uint32_t freq_in_hz = 2;
/* Calculate the delay in terms of bsp_delay_units */
const uint32_t delay = (bsp_delay_units) / freq_in_hz;
/* LED type structure */
bsp_leds_t leds;
/* LED state variable */
ioport_level_t level = IOPORT_LEVEL_HIGH;
/* I2C HAL Entry Function */
master_run ();
/* Get LED information for this board */
R_BSP_LedsGet (&leds);
/* If this board has no LEDs then trap here */
if (0 == leds.led_count)
{
while (1)
{
; // There are no LEDs on this board
}
}
while (1)
{
/* I2C HAL Read from slave device */
master_read ();
R_BSP_SoftwareDelay (delay, bsp_delay_units);
/* Determine the next state of the LEDs */
if (IOPORT_LEVEL_LOW == level)
{
level = IOPORT_LEVEL_HIGH;
}
else
{
level = IOPORT_LEVEL_LOW;
}
/* Update all board LEDs */
for (uint32_t i = 0; i < leds.led_count; i++)
{
g_ioport.p_api->pinWrite (leds.p_leds[i], level);
}
/* Delay */
R_BSP_SoftwareDelay (delay, bsp_delay_units);
}
}
/***********************************************************************************************************************
End of function sci_i2c_hal_module_guide_project
***********************************************************************************************************************/
The following is the output i received.
Output:
Read from reg = 0x9
SSP ERROR=0x12
SSP ERROR=0x12
SSP ERROR=0x12
SSP ERROR=0x12
SSP ERROR=0x12
SSP ERROR=0x12
SSP ERROR=0x12
Slave I2C test screen shot using bridge control panel.
Please help,
Thanks in advance.