/**@fn char Encoder_Read(char command, long *result) *@brief Reads from a register on the LS7366R encoder chip *@param [in] command A valid encoder command. Use the symbolic constants in Encoder.h *@param [in] *result pointer to a long value to store the result to * *This function reads from a register on the LS7366R encoder chip over SPI. It stores the result to the location pointed to by *result. *NOTE: Not all registers are longs (and depending on configuration, none of them might be), so it is up to the user to interpret the *returned value correctly. For READCNT commands, if the CNTR register is set to be less than 4 bytes, it will store the returned data *in the upper n bytes of the long, MSBF, where n is the number of bytes CNTR is set up to be. For all other commands, it stores the value *in the lower bytes. *NOTE: Interrupts are disabled while this operation communicates over the SPI bus. Care should be taken that critical interrupts do not *happen during the operation, as they will be ignored. */ char Encoder_Read(char command, long *result) { ENCODER_COMMAND genCom; Encoder_Generate_Command(command, &genCom); Serial_Print_String("\r\nGenerated Command: "); Serial_Print_Int((int)genCom._COMMAND, 2); cli(); Encoder_Initialize_SPI(); //bring encoder SS pin low to enable communications Pin_Set('B', SSPIN_ENC, 0); switch(command) { case READMDR0: case READMDR1: SPI_Send_Byte(genCom._COMMAND); *result = SPI_Read_Byte(); break; case READCNT: SPI_Send_Byte(genCom._COMMAND); *result = SPI_Read_Byte(); *result = *result<<8; *result |= SPI_Read_Byte(); *result = *result<<8; *result |= SPI_Read_Byte(); *result = *result<<8; *result |= SPI_Read_Byte(); } Pin_Set('B', SSPIN_ENC, 1); sei(); return 1; }
void Pin_Toggle(tPinName pin) { // Check for valid pin name if (pin == NONE || pin == ERR) return; // Pin is an input if (pins[pin].state == HiZ) return; // Toggle Pin if (pins[pin].state == LOW) Pin_Set(pin, HIGH); else Pin_Set(pin, LOW); }
int main(void) { // Clock (80MHz) SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // Init peripherals // Init Red LED Pin Pin_Init(PF1); Pin_Set(PF1, LOW); // I2C0 I2C_Init(I2C0); I2C_Enable(I2C0); // Init Objects PCA9557 pca9557 = PCA9557(I2C0); pca9557.set(P2, LOW); pca9557.set(P3, LOW); while(1) { Pin_Toggle(PF1); pca9557.toggle(P2); delay(0.2); } }
int main(void) { // Clock (80MHz) SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // Init LEDs Pin_Init(rLED); Pin_Set(rLED, LOW); // Init UART0 UART_Init(UART0); UART_Enable(UART0); setbuf(stdout, NULL); // Disable printf internal buffer // Init I2C0 I2C_Init(I2C0); I2C_Enable(I2C0); // Wait until user presses enter UART_ReadChar(UART0); // Scan for I2C addresses for(i=0; i < (1 << 7); i++) { printf("x%02x:", i); if (I2C_Write(I2C0, i, 0) == true) printf("* "); else printf(" "); Pin_Toggle(rLED); if (i % 8 == 7) printf("\r\n"); } // Indicator LED off Pin_Set(rLED, LOW); while(1); }
/**Disables the electromagnet*/ void Disable_Magnet() { Pin_Set(MAGPORT, MAGPIN, MAGOFF); }
/**Enables the electromagnet*/ void Enable_Magnet() { Pin_Set(MAGPORT, MAGPIN, MAGON); }
void Pin_Enable(tPinName pin) { Pin_Set(pin, LOW); }
void Pin_Disable(tPinName pin) { Pin_Set(pin, HiZ); }