hi , i wrote the following code that sends an adrdess through i2c and some data through dspi , the data of dspi is sent successfully but for i2c its not sent all this is my code:
/*
* Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* ###################################################################
** Filename : main.c
** Project : dspi_master_mpc5748g
** Processor : MPC5748G_324
** Version : Driver 01.00
** Compiler : GNU C Compiler
** Date/Time : 2017-03-14, 14:08, # CodeGen: 1
** Abstract :
** Main module.
** This module contains user's application code.
** Settings :
** Contents :
** No public methods
**
** ###################################################################*/
/*!
** @file main.c
** @version 01.00
** @brief
** Main module.
** This module contains user's application code.
*/
/*!
** @addtogroup main_module main module documentation
** @{
*/
/* MODULE main */
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "dspi1.h"
#include "clockMan1.h"
#include "pin_mux.h"
#include "dspi2.h"
#include "dmaController1.h"
volatile int exit_code = 0;
/* User includes (#include below this line is not maintained by Processor Expert) */
#include <stdint.h>
#include <stdbool.h>
#include "i2c1.h"
#define TIMEOUT 1000U
#define NUMBER_OF_FRAMES 10U
#define BUFFER_SIZE 10U
#define TRANSFER_SIZE 7
i2c_master_state_t i2c1MasterState;
/*!
\brief The main function for the project.
\details The startup initialization sequence is the following:
* - startup asm routine
* - main()
*/
int main(void)
{
/* Write your local variable definition here */
int master_send[BUFFER_SIZE] = {1, 2, 0, 4, 5, 6, 7, 8, 9, 10};
uint8_t master_receive[BUFFER_SIZE];
int i;
int j;
uint8_t masterTxBuffer[TRANSFER_SIZE] = {0x1,0,0,0x1,0x1,1,1};
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
/* SPI master configuration: clock speed: 500 kHz, 8 bits/frame, MSB first */
DSPI_MasterInit(DSPI0_INSTANCE, &dspi1State, &dspi1_MasterInitConfig0);
/* SPI slave configuration: clock speed: 500 kHz, 8 bits/frame, MSB first */
DSPI_SlaveInit(SPI0_INSTANCE, &dspi2State, &dspi2_SlaveInitConfig0);
/* Configure delay between transfer, delay between SCK and PCS and delay between PCS and SCK */
DSPI_MasterSetDelay(DSPI0_INSTANCE, 1, 1, 1);
I2C_DRV_MasterInit(INST_I2C1, &i2c1_MasterConfig0, &i2c1MasterState);
// send i2c address data
// send dspi sound data
for(i=0;i<BUFFER_SIZE;i++)
{
/* Start the blocking transfer */
DSPI_MasterTransferBlocking(DSPI0_INSTANCE, &master_send[i], master_receive, NUMBER_OF_FRAMES, TIMEOUT);
}
for (i = 0; i < TRANSFER_SIZE; i++)
{
/* Send a packet of data to the bus slave */
(void) I2C_DRV_MasterSendDataBlocking(INST_I2C1, &masterTxBuffer[i], TRANSFER_SIZE, true, OSIF_WAIT_FOREVER);
}
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;) {
if(exit_code != 0) {
break;
}
}
return exit_code;
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.1 [05.21]
** for the NXP C55 series of microcontrollers.
**
** ###################################################################
*/
this is what i get on logic analyzer.
the first 3 channels are for dspi which are sent fully, the last 2 channels are for i2c which is not sent fully, i also get this dissassembly:
can you please help me by telling me how to send the second array for i2c?
Hi,
do you have slave connected with slave address defined in the i2c master? So it can acknowledge first byte sent by master.
Zoom into a I2C signals and use I2C analyzer in Logic 2 tool to understand what is sent
BR, Petr
yes i do have a slave connected, where can i define the address? can you show me the way to do so?
this is what its showing:
its sending it to address 0100111 , i want to send to address 1110000
ok i was able to change the address but it still shows me +NAK and no data is sent, how can i make it +ACK and send my data?
is there i way i can send address with data without requiring the ack bit?
Yes Mr peter it is the slave register address i want to send data to