void PortBSpiInit(void) { LCD_CS = 0; SpiSendByte (0x40); SpiSendByte (0x01); SpiSendByte (0x00); LCD_CS = 1; }
void WritePortB(BYTE tempWr) { LCD_CS = 0; SpiSendByte (0x40); SpiSendByte (0x13); SpiSendByte (tempWr); LCD_CS = 1; }
void WritePortA(BYTE LcdEnable, BYTE LcdRS) { BYTE LcdControl1 = 0x00; LCD_CS = 0; SpiSendByte (0x40); SpiSendByte (0x12); LcdControl1 |= LcdEnable<<6; // LCD Enable bit position is 1 LcdControl1 |= LcdRS<<7; SpiSendByte (LcdControl1); LCD_CS = 1; }
/* The SPIWrite function transmits a given user buffer over the SPI. */ long SpiWrite_Init(unsigned char *pUserBuffer, unsigned short usLength) { unsigned char ucPad = 0; // // Figure out the total length of the packet in order to figure out if there is padding or not // if(!(usLength & 0x0001)) { ucPad++; } fWlanInterruptDisable(); //while(!WIFI_CS_CHECK()){}; WIFI_CS_LOW(); if (pUserBuffer[6]==0&&pUserBuffer[7]==0x40) Delay(1); pUserBuffer[0]=0x01; pUserBuffer[1]=((usLength+ucPad) & 0xff00) >> 8; pUserBuffer[2]=(usLength+ucPad) & 0xff; pUserBuffer[3]=0; pUserBuffer[4]=0; long count=0; for (int i = 0; i < 4; i++) { SpiSendByte((uint8_t)pUserBuffer[i]); count++; } if (pUserBuffer[6]==0&&pUserBuffer[7]==0x40) Delay(1); for (int i = 4; i< usLength+5; i++) { SpiSendByte((uint8_t)pUserBuffer[i]); count++; } if (ucPad >0){ SpiSendByte(0); count++; } // while (SPI_I2S_GetFlagStatus(WIFI_SPI, SPI_I2S_FLAG_RXNE) == RESET); Delay(10); WIFI_CS_HIGH(); EXTI_ClearITPendingBit(EXTI_Line8); //enable EXIT_IRQ from CC3000 fWlanInterruptEnable(); return count; }
void SpiWriteBytes(SpiDevice *const dev, int numBytes, uint8_t data[]) { SetChipSelectLow(dev); for (int byte = 0; byte < numBytes; byte++) { SpiSendByte(dev, data[byte]); } SetChipSelectHigh(dev); }
/* The SPIWrite function transmits a given user buffer over the SPI. */ long SpiReceive(unsigned char *pUserBuffer) { //disable interrrupt fWlanInterruptDisable(); WIFI_CS_LOW(); //Delay(1); wlan_tx_buffer[0]=0x03; wlan_tx_buffer[1]=0x0; wlan_tx_buffer[2]=0x0; wlan_tx_buffer[3]=0x0; wlan_tx_buffer[4]=0x0; ubRxMax=5; ubTxMax=5; ubTxIndex = 1; ubRxIndex = 0; wifi_state=1;//rx header SpiSendByte(wlan_tx_buffer[0]);//send first next are sent on int SPI_I2S_ITConfig(WIFI_SPI, SPI_I2S_IT_TXE, ENABLE); // WIFI_CS_HIGH(); // EXTI_ClearITPendingBit(EXTI_Line8); // fWlanInterruptEnable(); return 0;//FIXME THIS RETURNED COUNT }
/* The SPIWrite function transmits a given user buffer over the SPI. */ long SpiWrite(unsigned char *pUserBuffer, unsigned short usLength) { unsigned char ucPad = 0; // // Figure out the total length of the packet in order to figure out if there is padding or not // if(!(usLength & 0x0001)) { ucPad++; } while(!(WIFI_CS_CHECK() && fWlanReadInteruptPin())) { Delay(1); }; fWlanInterruptDisable(); WIFI_CS_LOW(); pUserBuffer[0]=0x01; pUserBuffer[1]=((usLength+ucPad) & 0xff00) >> 8; pUserBuffer[2]=(usLength+ucPad) & 0xff; pUserBuffer[3]=0; pUserBuffer[4]=0; if (ucPad >0){ pUserBuffer[usLength+5]=0; } ubTxIndex = 1;//index to 1 because I send first byte by hand ubTxMax = usLength+ucPad+5; ubRxIndex = 0;//index to 1 because I send first byte by hand ubRxMax = usLength+ucPad+5; wifi_state=0; SpiSendByte((uint8_t)pUserBuffer[0]);//first byte send int send the rest SPI_I2S_ITConfig(WIFI_SPI, SPI_I2S_IT_TXE, ENABLE); return 0;//FIXME RETURN COUNT? }
// 发送数据或指令 // DC : 数据或指令 // info : 发送的信息 void LcdWriteDC(u8 DC, uint8_t info) { LcdEnable(TRUE); if( DC == DATA) LCD_DC_HIGH(); else LCD_DC_LOW(); Delaynus(5); SpiSendByte(info); LcdEnable(FALSE); }
/* while the SPI is in IDLE state. */ void SPI2_IRQHandler(void) { /* SPI in Receiver mode */ if (SPI_I2S_GetITStatus(WIFI_SPI, SPI_I2S_IT_RXNE) == SET) { if (ubRxIndex < ubRxMax && ubRxIndex < SPI_BUFFER_SIZE) { /* Receive Transaction data */ wlan_rx_buffer[ubRxIndex++] = SPI_I2S_ReceiveData(WIFI_SPI); if (wifi_state == 1 )//rx header { if(ubRxIndex == 5){ unsigned char lsb_size; int size; size=wlan_rx_buffer[3]; lsb_size=wlan_rx_buffer[4]; size = (size << 8) + lsb_size; for (int i = 0; i < size; i++) { wlan_tx_buffer[i]= 0; } wifi_state=2; //rx body ubTxMax = size; ubTxIndex = 1 ; ubRxMax = size + 5; SpiSendByte(wlan_tx_buffer[0]); //sends first byte so next are sent by interrupt SPI_I2S_ITConfig(WIFI_SPI, SPI_I2S_IT_TXE, ENABLE); } }else if (wifi_state==2)//rx body { if (ubRxIndex == ubRxMax){ //end reception WIFI_CS_HIGH(); EXTI_ClearITPendingBit(EXTI_Line8); fWlanInterruptEnable(); SPI_I2S_ITConfig(WIFI_SPI, SPI_I2S_IT_TXE, DISABLE); (*_pfRxHandler)(wlan_rx_buffer+5); } }else if (ubTxIndex == ubTxMax &&ubRxIndex == ubRxMax && wifi_state == 0){//end of transsmision WIFI_CS_HIGH(); EXTI_ClearITPendingBit(EXTI_Line8); fWlanInterruptEnable(); SPI_I2S_ITConfig(WIFI_SPI, SPI_I2S_IT_TXE, DISABLE); } } else { /* Disable the Rx buffer not empty interrupt */ SPI_I2S_ReceiveData(WIFI_SPI); //SPI_I2S_ITConfig(WIFI_SPI, SPI_I2S_IT_RXNE, DISABLE); } } /* SPI in Tramitter mode */ if (SPI_I2S_GetITStatus(WIFI_SPI, SPI_I2S_IT_TXE) == SET) { if ((ubTxIndex < ubTxMax && ubTxIndex < SPI_BUFFER_SIZE))//||wifi_state==1|| wifi_state==2) { /* Send Transaction data */ SPI_I2S_SendData(WIFI_SPI, wlan_tx_buffer[ubTxIndex++]); } else { /* Disable the Tx buffer empty interrupt */ SPI_I2S_ITConfig(WIFI_SPI, SPI_I2S_IT_TXE, DISABLE); } } //wlan_rx_buffer[0] = SpiSendByte(0); }