Starter the init function and implementation from registers

i2c
kerem 3 years ago
parent cfbb4a49ea
commit ec2a90186e

@ -64,14 +64,14 @@ typedef enum{
/*! Enum of possible I2C Address count */ /*! Enum of possible I2C Address count */
typedef enum{ typedef enum{
i2cAddressCountSingle, /*!< Only one adress for communication **DEFAULT** */ i2cAddressCountSingle, /*!< Only one address for communication **DEFAULT** */
i2cAddressCountDual /*!< Dual adresses for one device respondng to two adresses */ i2cAddressCountDual /*!< Dual addresses for one device respondng to two addresses */
}i2cAddressCount_t; }i2cAddressCount_t;
/*! Enum for clock strechning activation. Can only be implmented as Slave /*! Enum for clock strechning activation. Can only be implmented as Slave
* for more information : https://www.i2c-bus.org/clock-stretching/ */ * for more information : https://www.i2c-bus.org/clock-stretching/ */
typedef enum{ typedef enum{
i2cCLockStrechingDisable, /*!< We assume that the master and slave have compatible i2cClockStrechingDisable, /*!< We assume that the master and slave have compatible
Clock frequencies **DEFAULT** */ Clock frequencies **DEFAULT** */
i2cClockStrechingEnable /*!< In situations where an I2C slave is not able to co-operate i2cClockStrechingEnable /*!< In situations where an I2C slave is not able to co-operate
with the clock speed given by the master and needs to slow down. with the clock speed given by the master and needs to slow down.
@ -82,7 +82,7 @@ typedef enum{
typedef enum{ typedef enum{
i2cWakeUpDisabled, /*!< No wake up is possible this is the default mode also means that i2cWakeUpDisabled, /*!< No wake up is possible this is the default mode also means that
the sleep function is not implmentes **DEFAULT** */ the sleep function is not implmentes **DEFAULT** */
i2cWakeUpOnAddressMatch /*!< Wakes up on adress match, this can be harware dependent */ i2cWakeUpOnAddressMatch /*!< Wakes up on address match, this can be harware dependent */
}i2cWakeUpTypes_t; }i2cWakeUpTypes_t;
/*! Enum operation mode of the i2c channel */ /*! Enum operation mode of the i2c channel */
@ -113,14 +113,14 @@ typedef enum
} i2cState_t; } i2cState_t;
/*! Struture a an i2c channel with all the required propereties*/ /*! Struture a an i2c channel with all the required propereties*/
typedef struct typedef struct i2c_t
{ {
i2cCh_t channelNo; /*!< The harware channel to be used */ i2cCh_t channelNo; /*!< The harware channel to be used */
i2cMode_t mode; /*!< Master, Slave or Multymaster Modes */ i2cMode_t mode; /*!< Master, Slave or Multymaster Modes */
uint16_t adress; /*!< First and Main address of the device */ uint16_t address; /*!< First and Main address of the device */
uint16_t adressSecond; /*!< Second adress if dual adresse mode is configured */ uint16_t addressSecond; /*!< Second address if dual addresse mode is configured */
i2cAddressCount_t addresCount; /*!< Single or multiple */ i2cAddressCount_t addressCount; /*!< Single or multiple */
i2cAddressSize_t adressSize; /*!< 10 or 7 bit adress size */ i2cAddressSize_t addressSize; /*!< 10 or 7 bit address size */
i2cSpeed_t speed; /*!< Bus Speed */ i2cSpeed_t speed; /*!< Bus Speed */
i2cOpperationMode_t opperationMode; /*!< Blocking or non blocking polling, Int or DMA */ i2cOpperationMode_t opperationMode; /*!< Blocking or non blocking polling, Int or DMA */
i2cClockStreching_t streching; /*!< Clock Streching enable onyl in slave mode */ i2cClockStreching_t streching; /*!< Clock Streching enable onyl in slave mode */
@ -161,7 +161,7 @@ void i2cSetMode(i2c_t *i2cHardware, i2cMode_t mode);
* @param channel is the i2c hardware channel * @param channel is the i2c hardware channel
* @param size Is the Adress isze to be used 7 Bit or 10 Bit * @param size Is the Adress isze to be used 7 Bit or 10 Bit
* @param addressOne The forst address for the device * @param addressOne The forst address for the device
* @param addressTwo The second address for the device only if dual adress mode is not defined * @param addressTwo The second address for the device only if dual address mode is not defined
*/ */
void i2cSetAddress(i2c_t *i2cHardware, i2cAddressSize_t size, uint16_t addressOne, uint16_t addressTwo); void i2cSetAddress(i2c_t *i2cHardware, i2cAddressSize_t size, uint16_t addressOne, uint16_t addressTwo);
@ -206,6 +206,12 @@ void i2cSetTimeout(i2c_t *i2cHardware, uint8_t timeout);
* @brief Resets the i2c Periferal to it's inital state. * @brief Resets the i2c Periferal to it's inital state.
* @param channel is the beforehand declared i2c channel with his opperation modes * @param channel is the beforehand declared i2c channel with his opperation modes
*/ */
void i2cPeriferalReset(i2c_t *i2cHardware);
/**
* @brief Resets the i2c to it's inital state.
* @param channel is the beforehand declared i2c channel with his opperation modes
*/
void i2cReset(i2c_t *i2cHardware); void i2cReset(i2c_t *i2cHardware);
/************************************************************************************************** /**************************************************************************************************
@ -333,7 +339,7 @@ void i2cBusClear(); // I2C Standart : in case if SCL is stuck
***************************************************************************************************/ ***************************************************************************************************/
/** /**
* @brief This function will scan every for possible adresses to discover devices on the bus. * @brief This function will scan every for possible addresses to discover devices on the bus.
* And write them to the Devices list given to him. This function will not discover more * And write them to the Devices list given to him. This function will not discover more
* devices than what he is told. * devices than what he is told.
* @param channel is the beforehand declared i2c channel with his opperation modes * @param channel is the beforehand declared i2c channel with his opperation modes

@ -28,7 +28,6 @@ void i2cInit(i2c_t *i2cHardware)
{ {
i2cReset(i2cHardware); i2cReset(i2cHardware);
RCC->APB1ENR |= i2cBus_En_bitPos[i2cHardware->channelNo]; RCC->APB1ENR |= i2cBus_En_bitPos[i2cHardware->channelNo];
} }
void i2cReset(i2c_t *i2cHardware) void i2cReset(i2c_t *i2cHardware)
@ -37,3 +36,4 @@ void i2cReset(i2c_t *i2cHardware)
RCC->APB1RSTR &= ~(1 << i2cBus_Rst_bitPos[i2cHardware->channelNo]); RCC->APB1RSTR &= ~(1 << i2cBus_Rst_bitPos[i2cHardware->channelNo]);
} }

@ -78,3 +78,4 @@ list(APPEND EXTRA_LIBS sub::usart)
list(APPEND EXTRA_LIBS sub::timer) list(APPEND EXTRA_LIBS sub::timer)
list(APPEND EXTRA_LIBS sub::init) list(APPEND EXTRA_LIBS sub::init)
list(APPEND EXTRA_LIBS sub::spi) list(APPEND EXTRA_LIBS sub::spi)
list(APPEND EXTRA_LIBS sub::i2c)

@ -4,7 +4,6 @@
#include "usart.h" #include "usart.h"
#include "ascii.h" #include "ascii.h"
#include "timer.h" #include "timer.h"
#include "spi.h"
#include "i2c.h" #include "i2c.h"
void timer_test(timerNo_t timer, pinNo_t pin) void timer_test(timerNo_t timer, pinNo_t pin)
@ -46,7 +45,7 @@ int main(int argc, char *argv[])
uint8_t i = 0; uint8_t i = 0;
// making array with all available timers // making array with all available timers
timerNo_t timers[MAX_TIMER_CHANNEL_COUNT] = {timer_1, timer_2, timer_3, timer_14, timer_16, timer_17}; //timerNo_t timers[MAX_TIMER_CHANNEL_COUNT] = {timer_1, timer_2, timer_3, timer_14, timer_16, timer_17};
delayInitMs(8000000, 1000); // Clock Freq and Divider for ARM library delayInitMs(8000000, 1000); // Clock Freq and Divider for ARM library
@ -55,7 +54,6 @@ int main(int argc, char *argv[])
setupInit(); // This is the sescond call of System init the assebly start code is calling it before the main. setupInit(); // This is the sescond call of System init the assebly start code is calling it before the main.
usartInit( usart2, usartInit( usart2,
pinA2, pinA2,
pinA15, pinA15,
@ -66,7 +64,7 @@ int main(int argc, char *argv[])
//clears screen and send the wellcome messgae //clears screen and send the wellcome messgae
print_Usart(usart2, ASCII_clear); print_Usart(usart2, ASCII_clear);
print_Usart(usart2, "HEllooo to our KED project\n\r"); print_Usart(usart2, "Hello to our KED project\n\r");
//blinks 10 times to indicate the sicsessfull init if the device //blinks 10 times to indicate the sicsessfull init if the device
@ -75,38 +73,51 @@ int main(int argc, char *argv[])
pinToggle(pinB3); pinToggle(pinB3);
delayMs(100); delayMs(100);
} }
pinWrite(pinB3,0);
pinInit(pinA5);
pinInit(pinA6);
pinInit(pinA7);
pinSetAlternate(pinA5, 0); // SPI1_SCK pinWrite(pinB3,0);
pinSetAlternate(pinA6, 0); // SPI1_MISO
pinSetAlternate(pinA7, 0); // SPI1_MOSI
spi_init(SPI_CH_1); // Pin configuration for i2c
pinInit(pinB6);
pinInit(pinB7);
pinConfig(pinB6, alternate, openDrain, none, veryFast);// I2C SCL
pinConfig(pinB7, alternate, openDrain, none, veryFast);// I2C CSA
pinSetAlternate(pinB6, 1);
pinSetAlternate(pinB7, 1);
i2c_t i2c_1;
i2c_1.channelNo = I2C_CH_1;
i2c_1.mode = i2cModeMaster;
i2c_1.address = 0x33;
i2c_1.addressSecond = 0;
i2c_1.addressCount = i2cAddressCountSingle;
i2c_1.addressSize = i2cAddressSizeSevenBits;
i2c_1.speed = i2cSpeedStandart;
i2c_1.opperationMode = i2cOpperationPolling;
i2c_1.streching = i2cClockStrechingDisable;
i2c_1.timing = 0x2000090E; // Taken from stm code generator
i2c_1.wakeOn = i2cWakeUpDisabled;
i2c_1.state = i2cNotInitialized;
i2cInit(&i2c_1);
/*
for(i = 0 ; i < 20 ; i++) { for(i = 0 ; i < 20 ; i++) {
delayMs(50); delayMs(50);
pinToggle(pinB3); pinToggle(pinB3);
delayMs(50); delayMs(50);
} }
for(i = 10; i > 0; i--) {
spi_trx(SPI_CH_1, 0xAE);
}
for(i = 0 ; i < 10 ; i++) { for(i = 0 ; i < 10 ; i++) {
delayMs(100); delayMs(100);
pinToggle(pinB3); pinToggle(pinB3);
delayMs(100); delayMs(100);
} }
*/
//timer_capture_compare_test(timer_2); //timer_capture_compare_test(timer_2);
//print_Usart(usart2, "All is working fine \r\n"); print_Usart(usart2, "All is working fine \r\n");
while(1) while(1)
{ {

Loading…
Cancel
Save